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.


  1. Nice find Klevo.

    I also found this out the hard way. It seems that my Apache setup on Ubuntu Server also requires me to set the RewriteBase.

    I think this is a pretty well-ish documented thing, though. I seemed to find a solution within minutes after a couple of Google searches.

    What I don’t understand, though, is that the use of RewriteBase doesn’t seem to break hosts that don’t initially require it to be set. For example, I develop websites with CakePHP on my home server (with RewriteBase), then upload it to a web host. I don’t bother removing the RewriteBase line from the production version, though, and it works just fine. So I don’t understand why it isn’t included in the CakePHP .htaccess files by default!? :-/

Comments are closed.