2007-10-18

Enabling CakePHP 1.1 on Lighttpd 1.5

A lot of people out there are trying to figure out how to get CakePHP 1.1x running on Lighttpd 1.5. Here is the solution. Please follow it carefully:
#### Disable BASE_URL ####

 a) Open the file "app/config/core.php"
 b) Make sure that the BASE_URL constant is commented out
 
#### REDIRECT_URI fix ####

 a) Open the file "cake/basics.php"
 b) Go to the function "setUri"
 c) Find this line:

   if (env('HTTP_X_REWRITE_URL')) {
    
  Replace with this:
  
   if( env('REDIRECT_URI') ) {
    $uri = env('REDIRECT_URI');
   }
   else if (env('HTTP_X_REWRITE_URL')) {

#### Add rewrite rules to lighttpd.conf ####

 a) Enable mod_rewrite in lighttpd.conf
 b) Add this to lighttpd.conf:

   url.rewrite-once = (
    "^/(css|files|img|js|stats)/(.*)$" => "/$1/$2",
    "^/(.*)$" => "/index.php?url=$1"
   )

8 comments:

Anonymous said...

Thanks!!!

Anonymous said...

Might want to change the second regex so that URLs with GET query strings in them still work:

"^/([^?]*)(\?(.+))?$" => "/index.php?url=$1&$2"

cinar said...

Use this for latest CakePHP:

$HTTP["host"] == "domain.name" {
url.rewrite-once = (
"^/(css|files|img|js|stats)/(.*)$" => "app/webroot/$1/$2",
"^/(.*)$" => "app/webroot/index.php?url=$1"
)
}

www.zdo.com

randy said...

For the $_GET to work properly, the regex for the second rule needs to be modified ever so slightly from Anonymous' post from Nov, 2007.

"^/([^?]*)(?:\?(.+))?$" => "/index.php?url=$1&$2"

Notice the ?: which prevents the question mark from being captured as part of the first query parameter.

internet marketing melbourne said...

I was looking for crucial information on this subject. The information was important as I am about to launch my own portal. Thanks for providing a missing link in my business.

website design hampshire said...

Somebody wrote an excellent post on how to make CakePHP work on LigHTTPD. It didn't work for me right away because for some reason mod_rewrite or my CakePHP settings are different from the "default" behavior.

Affordable web hosting service said...

Glad to visit this professional blog. I was looking for same information.. wanted to know enabling CakePHP 1.1 on Lighttpd 1.5". Great for guys for sharing this code.

Unknown said...

Great post I love reading it. actually I was searching this kind of knowledgeable article on this topic and I am very pleased to read it thanks for your posting. Love it.
online marketing