Using supervisord for Nginx+FastCGI+PHP

I was having problems with spawn-fcgi-standalone occasionally resulting in dead PHP processes, which caused 502 Bad Gateway errors on my site. Crontabbing an /etc/init.d/init-fastcgi start didn’t help much, so I looked for other ways to do it. Supervisord looked promising.

Here’s how to get Supervisord:

apt-get install python-setuptools
easy_install supervisor


Here’s what to add to /etc/supervisord.conf:


So far, so good. When I kill the php process, supervisord starts it back up. Progress!

supervisord doesn’t come with an init.d script, but you can get one for Ubuntu.

  • doddy

    But…what is the root of the problem? Why is PHP dying? Can you sleep at night without knowing this?

  • I came across some webpages that suggested php-fcgi wasn’t the most reliable way to do it (long pages would die, etc.), and that fpm or supervisord might be better. This way, I can keep the extraneous bad gateway errors from my error logs, and focus on what’s causing the occasional process to die.

  • perusio

    Have you heard of Monit? I use for supervising both nginx and php-cgi. It’s written in C and not in Python.

    I’ve published by monit configuration for supervising MariaDB (MySQL), nginx, and php-cgi, among other things on github: just in case you’re interested in checking out monit.

  • Thanks for sharing!

  • Supervisord has been great to work with. However, sometimes it seems to not want to log to the specified stdout_logfile . Even tho there is absolutely std out.

    Have you ever had issues with supervisord logging to stdout_logfile ?

  • Thanks. very helpful.. Finally configured it for my blog with auto start. No worries about crashing php5-cgi process.

  • @warren: Yeah! i’m seeing the same thing. Ever figure it out?

  • Yea, supervisord only logs in bursts when there is enough data for the particular process. In my case it was only writing when there was ~1K worth of data (and it was a timed job, so it appeared to be related to time – but that was not the case).

    I have also seen some strange behavior with the log rotation. For example, if you are logging to test.log, sometimes you will find it is logging to test.log.5

    A ls -lart helps with that :)

    All things considered, supervisord has been doing a great job. We have been using it in production for a couple months.