In a recent blog post – It's LEMP Not LAMP – I discussed about making the switch to using NGINX (pronounced Engine-X). I had little-to-no issues getting by basic Wordpress blogs up and running. However, for some reason I couldn't get my older CakePHP sites up and working.
I was racking my brain forever, trying everything I could think of with the rewrite rules – thinking for sure this must be the root of the cause. In the end I thought it might just be an issue with the version of CakePHP I was using, as it was an older version (1.2.x). However, I just grabbed a clean copy from CakePHP's Github of 1.2.10 and got it up and running without issues.
I'm of course even more confused at this point, so why am I writing this blog post you ask? The answer is simple, if you're having issues with getting an old CakePHP site to work on NGINX, try upgrading your CakePHP version.
After getting a fresh copy of CakePHP, the existing rewrite rules I already had in place worked like a charm. Not only that, I even tried a few of the different variations suggested and they all seemed to work.
In case you came here looking for the rewrite rules, either of these from CakePHP's website worked perfectly (CakePHP 1.2 NGINX Conf or CakePHP 1.3 NGINX Conf):
Or for 1.3:
The only difference appears to be ?q is replaced with ?url. As mentioned, both seemed to work for me… Hopefully if you're stumbling around with this, you can simply update your CakePHP version and move on instead of wasting hours like I did. Published on Sep 10, 2012 Tags: CakePHP Tutorial
| nginx
| rewrite
Did you enjoy this article? If you did here are some more articles that I thought you will enjoy as they are very similar to the article
that you just finished reading.
No matter the programming language you're looking to learn, I've hopefully compiled an incredible set of tutorials for you to learn; whether you are beginner
or an expert, there is something for everyone to learn. Each topic I go in-depth and provide many examples throughout. I can't wait for you to dig in
and improve your skillset with any of the tutorials below.
Two important keys to note:
server {
listen 80;
server_name example.com;
access_log /var/www/example.com/log/access.log;
error_log /var/www/example.com/log/error.log;
location / {
root /var/www/example.com/public/app/webroot/;
index index.php index.html index.htm;
if (-f $request_filename) {
break;
}
if (-d $request_filename) {
break;
}
rewrite ^(.+)$ /index.php?q=$1 last;
}
location ~ .*\.php[345]?$ {
include /etc/nginx/fcgi.conf;
fastcgi_pass 127.0.0.1:10005;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME
/var/www/example.com/public/app/webroot$fastcgi_script_name;
}
}
…
rewrite ^(.+)$ /index.php?url=$1 last;
…
Related Posts
Tutorials
Learn how to code in HTML, CSS, JavaScript, Python, Ruby, PHP, Java, C#, SQL, and more.