LightTPD and CakePHP setup in subdirectories
I faced the challenge to install CakePHP under LightTPD. All works smoothly as long as I deploy projects in document root of domain. But when I want to setup CakePHP in subdir all goes wrong.
The source of the problem is env('PHP_SELF'). In the default LightTPD/PHP instalation it is not working. You should tweak some settings.
- Add cgi.fix_pathinfo = 1 in your php.ini
- Add "broken-scriptfilename" => "enable" into lighttpd.conf at fastcgi.server section.
- Add '/subdir' into rewrite rules to emulate apache's RewriteBase
- In webroot/index.php define('WEBROOT_DIR', basename(dirname(dirname(__FILE__))));
fastcgi.server = ( ".php" =>
((
"socket" => "/usr/local/lighttpd/fcgi/wortex/socket",
"check-local" => "disable",
"broken-scriptfilename" => "enable"
))
)
$HTTP["host"] == "example.com" {
server.document-root = "/var/www/example.com/"
url.rewrite-once = (
"/project1/(css|files|img|js|stats)/(.*)" => "/project1/webroot/$1/$2",
"^/project1/([^.]+)$" => "/project1/index.php?url=$1",
"/project2/(css|files|img|js|stats)/(.*)" => "/project2/webroot/$1/$2",
"^/project2/([^.]+)$" => "/project2/index.php?url=$1"
)
}
'project1' and 'project2' are dirs made by bake.php. Url in browser looks like http://example.com/project1/controller/action








$HTTP["host"] =~ "^(subdomain\.)?example.com$" {
server.document-root = "/var/www/cake/"
url.rewrite = (
"/cakecms/(.*)" => "cakecms/webroot/$1/$2",
"/cakecms" => "cakecms/webroot/$1/$2",
"^/(css|files|img|js|stats)/(.*)$" => "app/webroot/$1/$2",
"^/(.*)$" => "app/webroot/index.php?url=$1"
)
}
I have to put this line:
"/cakecms" => "cakecms/webroot/$1/$2",
because if i call subdomain.example.com/cakecms without the trailing slash, it donesn't work... well, for each project i have to make two rules:
"/project_name/(.*)" => "project_name/webroot/$1/$2",
"/project_name" => "project_name/webroot/$1/$2",
One line with trailing slash, and another without it, i know... maybe im writing more code, but... it works !!!! :)
i hope it works for you people!
url.rewrite-once = (
"/(css|files|img|js|stats)/(.*)" => "/$1/$2",
"^/(.+)/?$" => "/index.php?url=$1"
)
"^/(test.php)(.*)$" => "/test.php$2",
to url.rewrite-once for testing in 1.2
url.rewrite-once= (
"/(css|files|img|js|stats)/(.*)" => "/$1/$2",
"^/(test.php)(.*)$" => "/test.php$2",
"^(.*)$" => "/index.php?url=$1"
)
http://thefaultandfracture.blogspot.com/2007/10/enabling-cakephp-11-on-lighttpd-15.html
url.rewrite-once = (
"/(.*)\.(.*)" => "$0",
"/(css|files|img|js)/" => "$0",
"^/([^.]+)$" => "/index.php?url=$1"
)
More info check out this thread on google groups
http://groups.google.com/group/cake-php/browse_thread/thread/2e1c408e723551e9/59d93ccb66552419?lnk=gst&q=lighttpd&rnum=7#59d93ccb66552419
Don't forget to turn on mod_rewrite :)
Comments are closed for articles over a year old