Solving PHP-FPM 502 Errors?


I think this has been discussed before, but I’m wondering if anyone has made any progress.

I was having problems with PHP 5.2 + Nginx that Dreamhost provide hitting 502 Bad Gateway errors. I believe this is due to a PHP process locking/dying and not being able to be killed & restarted. The only way I could fix the problem was manually using ‘killall -s 9 php5.cgi’ to force kill the processes & then restart nginx (’/etc/init.d/nginx restart’).

I have since installed my own version of PHP (5.3.12) with PHP-FPM enabled, but I am still getting the same problem even with PHP-FPM. All of the PHP-FPM processes will stop responding & I’ll get the dreaded 502 again. The only way to get them back is to use killall again. Even restarting the daemon doesn’t work. Instead it creates a new instance & uses twice the memory.

I have no idea how to fix this, and it appears neither do the (lovely) people at DreamHost support. At the minute I’m stuck as I thought upgrading to PHP-FPM was supposed to fix this problem & yet it seems to still be there for me.

Does anyone have any ideas at all? Any tips, no matter how small, would be greatly appreciated.

I had success to configurate my VPS without 502 error in nginx.

i installed :
1 - i use monit to monitoring the nginx process
2 - download and put it on cron to control the php5.cgi process
3 - download and install the JJ’s VPS Memory Manager from

With this things my vps dont have anymore 502 error nginx



i still have errors (502 errors)…

i have this config in monit:

check process nginx
with pidfile /dh/nginx/servers/httpd-xxxxxxx/var/logs/ #Pid file for nginx in my case it located in /opt/nginx/logs/
start program = "/etc/init.d/nginx start"
stop program = "/etc/init.d/nginx stop"
if failed host port 80 protocol HTTP then restart #set your server IP that runs nginx
if failed host port 80 protocol HTTP then alert
if 5 restarts with 5 cycles then alert
#check file webserver_count_php with path /tmp/php

if match “\b[0-1][0-5]?|15\b” then alert # 0…15

if match “\b[0-1][0-5]?|15\b” then exec “/usr/bin/killall -9 php53.cgi” # 0…15

check file webserver_response with path /tmp/web
if match “502” then exec “/usr/bin/killall -9 php53.cgi”

if match “502” then exec “/etc/init.d/nginx restart”

if match “502” then alert
depends on nginx

any can help with monit config?


Hello hussan,

We are struggling with DH and 502/504 errors…

I’v noticed that check file won’t return you/us the 502, 504, 200 etc that is supposed to.

What we want is

check program script with path “/path/to/

But check program was introduced on monit 5.3 and I guess you have 5.1.1.

I’m trying to put all my steps on my lousy blog

(Isto está fodido! :wink: