Setting up CakePHP with fastCGI
Posted by Jason on July 2, 2007 at 11:36 am
I’ve been using CakePHP for quite a while now with no .htaccess issues at all, either running locally or on hosted sites. That all changed last night when I couldn’t get it to work at all on one of my budget hosting sites. Instead of my application all I saw were 500 Internal Server Errors.
I found that the issue was definitely down to one line in the root .htaccess (which was unmodified from the original CakePHP download):
RewriteRule (.*) app/webroot/$1 [L]
Unfortunately my cheaper hosting doesn’t allow me access to the error logs so it was difficult to diagnose the problem. By 11:00 last night I was certainly not in a good mood and no closer to an answer. I managed to Google plenty of references to similar issues but none solved my problem.
This morning I resorted to the hosting company themselves and within an hour they came up trumps! My thanks to Rob at VirtualNames support who not only worked it out, he even changed the file for me!
It looks like the problem is that the mod_rewrite rules don’t like fastcgi, which is the preferred option for this hosting account - it seems to try and redirect the internal URLs for fast cgi causing a rewriting loop. VirtualNames support felt it would probably work if the PHP mode is switched back to module mode, but they also came up with a fix to the .htaccess in the domain folder to (the root .htaccess for the CakePHP installation):
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_URI} !^/cgi-bin/
RewriteRule ^$ app/webroot/ [L]
RewriteCond %{REQUEST_URI} !^/cgi-bin/
RewriteRule (.*) app/webroot/$1 [L]
</IfModule>
This stops it trying to redirect the fastcgi internal access urls, and appears to cure the problem. It looks like the other .htaccess files do not need changing. .htaccess and rewrite rules are still a bit of a black art to me. After this they are going on my list of things to pick up!
I can also recommend VirtualNames as a budget hosting solution should you need one. Their support people actually do…erm…’support’ ![]()
Hi, u make me very happy. I tried everything to solve exactly the same issue. You save me so much time with your description. THX!
It works now!!!!
Great Job
Comment by Norim — May 27, 2008 @ 1:56 pm