LightTPD and CakePHP setup in subdirectories

By Anton Bobrov (baverman)
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.

  1. Add cgi.fix_pathinfo = 1 in your php.ini
  2. Add "broken-scriptfilename" => "enable" into lighttpd.conf at fastcgi.server section.
  3. Add '/subdir' into rewrite rules to emulate apache's RewriteBase
  4. In webroot/index.php define('WEBROOT_DIR', basename(dirname(dirname(__FILE__))));
Here is piece of my lighttpd.conf:
Download code 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

 

Comments 164

CakePHP Team Comments Author Comments
 

Comment

1 Not compatible with other developers in a team environment

I am working on a project with other developers who run their code on their local Apache servers. Thus changing webroot/index.php file is not a good solution for me. I want to keep our code as portable as possible while relying on configuration to kink out the differences.
Posted Dec 24, 2006 by Dat Chu
 

Comment

2 You may create custom index.php

You may create lighttpd version of index.php (lightttpd-index.php for example) and change rewrite rules.
Posted Dec 25, 2006 by Anton Bobrov
 

Comment

3 Lighthttpd Without the Subdirectory

Here's the rewrite rule to get cakephp working in lighttpd without the subdirectory structure outlined here.

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 :)
Posted Apr 20, 2007 by DF
 

Comment

4 Solution to getting Cake 1.1 running on Lighttpd 1.5

Here is the complete solution to getting Cake 1.1x running on Lighttpd 1.5x

http://thefaultandfracture.blogspot.com/2007/10/enabling-cakephp-11-on-lighttpd-15.html
Posted Oct 18, 2007 by Brendon Crawford
 

Comment

5 for test suite

I add
"^/(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"
)
Posted Nov 1, 2007 by Sylka Andriy
 

Comment

6 parseExtensions for 1.2

lightys' rewrite mod usually sends 404 with extensions, so i changed the rewrite rule:

url.rewrite-once = (
"/(css|files|img|js|stats)/(.*)" => "/$1/$2",
"^/(.+)/?$" => "/index.php?url=$1"
)
Posted Jul 10, 2008 by Daniel M