CakePHP and some web hosts

CakePHP is quite a mature framework. Yet I often run into troubles with some more exotic hosting companies.

Yesterday I was deploying a site hosted at 1 & 1 Internet Ltd. For a few hours I was trying everything but still I got the same 500 internal error. Finally I traced the problem to mod_rewrite. It turned out that I need to add RewriteBase to all Cake’s .htaccess files. So if you’re deploying your lovely new site to 1 & 1 your root .htaccess file might look like this:

# Turn on PHP 5
AddType x-mapp-php5 .php
RewriteEngine on
RewriteBase /
RewriteRule ^$ app/webroot/ [L]
RewriteRule (.*) app/webroot/$1 [L]

mysqli_connect and socket support

Some web hosts use sockets for MySQL connection. Socket is the 6th parameter in mysqli_connect (or mysql_connect). Cake does not know about this 6th parameter. I submitted a ticked some time ago, but it was closed and the change not implemented.

The solution is however very simple. Depending on what driver you use, edit file dbo_mysqli.php or (dbo_mysql) in cake/libs/model/datasources/dbo/ and on line 94 (CakePHP 1.2 rev 6311) add the 6th parameter to the mysqli_connect function. Don’t forget to add the default socket value (I use null) to the $_baseConfig private variable of the DboMysqli class you’re just editing.

CakePHP and WebBaker

Recently I started using this wonderful PHP framework called CakePHP. It really moves the whole web development process to another level. It has got the MVC pattern, great community, good documentation, lots of people writing about it and there is the WebBaker. WebBaker is a PHP script that let’s you easily create all the files you need for your MVC pattern (model, controller, views). This saves you a lot of precious minutes.

Webbaker in action The CakePHP and WebBaker combination is deadly. You can have a functional element in your site like in 1 minute. All you need to do is create a table in the database and use WebBaker to generate appropriate files. At this point when you have written exactly 0 lines of code you have a fully functional interface where you can list, view, edit, add and delete items from database. This is possible due to the excellent scaffold functionality build in Cake. Then you can start writing your own code and smoothly replace the scaffolds. Try it, you’ll never want to go back.