NGINX (Engine-X) Rewrite Rules For CakePHP
April 17th, 2008
I’ve been doing some work with NGINX of late and anyone familiar with CakePHP will know that it ships out of the box with Apache .htaccess files to make sure that the URL’s are devoid of there query string.
Anyway, enough talk, if you want to host cakephp on NGINX, you’ll need to use a vhost like so:
server {
listen 80;
server_name somedomain.com;
access_log /var/www/logs/somedomain.access.log main;
error_log /var/www/logs/somedomain.error.log info;
rewrite_log on;
# rewrite rules for cakephp
location / {
root /var/www/sites/somedomain.com/current;
index index.php index.html;
# If the file exists as a static file serve it
# directly without running all
# the other rewite tests on it
if (-f $request_filename) {
break;
}
if (!-f $request_filename) {
rewrite ^/(.+)$ /index.php?url=$1 last;
break;
}
}
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME \
/var/www/sites/somedomain.com/current$fastcgi_script_name;
include fastcgi_params;
}
}
Fixing random PHP crashes on IIS 6 recorded as PHP memory leaks
September 30th, 2007
I recently came accross a serious problem that seems to be relativly un-documented bar other people raising bug tickets on bugs.php.net.
If you are having problems with PHP on IIS where you get a couple page views from your application then you just get a blank screen? If so then read on….
There was nothing in the Event Log for applicatons or system, so I tried re-starting IIS; with no luck. This particular problem seemed to be happening tottaly silently with absolutly no record anywhere (php_error.log et al). I them re-started the whole box, and upon boot up I checked the Event viewer and there was an entry in the application log detailing a memory leak in “php.exe”. So, a memory leak I thought, great…
Trawling the web I then found a document detailing how windows server kills off processes it deems to be at all ‘dangerous’. It does this silently (which is unbeliviably handy) and fitted with the problems I was encountering. Going on the presumption that it was indeed killing the PHP process (or more specifically the worker threads) I turned to the application pool configuration… And broke out alll my PHP apps into a seperate application pool. When they stoped working, I could just recycle the pool and they worked again for two requests. NB: Ive seen other peoples configurations take a couple more than 2 requests so bear that in mind if your having this problem.
So, by now I knew that it was windows killing of the process causing the problems, however I wasnst sure how to fix it.
I looked at the loaded modules in my PHP.ini, and found that removing all non-essential modules solved the problem. I then brought in one by one each PHP module, and found that it was not actually the modules them selves that were leaking, but just the order in which they were loaded causing the problem.
Yes, thats very crap. I couldnt find a more elegant solution to this, and I really hope this helps someone as I must have wasted a day of my life trying to solve this bloody problem! lol