How To Set Up Apache2 With mod_fcgid And PHP5 On Debian Lenny

A good article, I used to set up FCGI the same way. I had to find all the necessary info myself, when I first tried to use FCGI with a multi-site setup (separate PHP config, etc. for each site), but I'm glad that meanwhile somebody took the time to write it down. Smile

Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

FastCGI (aka. mod_fcgid) and the PHP_FCGI_CHILDREN variable

First things first: you should never set PHP_FCGI_CHILDREN to anything else than 0 if you use it with mod_fcgi. This is pretty well described in the mod_fcgi documentation.
Nonetheless I had this set to 5 for a long time and it did not cause any problems. Recently the server was upgraded from Debian Lenny to Squeeze and the server died even under minimum load. Even a couple (a dozen) PHP requests caused the PHP processes (php5-cgi) to push the CPU to 100% (actually it pushed the wait percentage up as if there was heavy disk I/O ... and soon the system started swapping too as if memory was depleted). I couldn't find the culprit for quite some time, but then came to a post about PHP_FCGI_CHILDREN and how one should set it to zero in case one uses it with FCGI. So I did it and it fixed the problem. The server started acting normal again.

It seems that the mod_fcgid in Lenny (2.2-1+lenny1) and in Squeeze (2.3.6-1) handle PHP_FCGI_CHILDREN a bit differently. At least I did not find anything else to be different (the PHP version was the same before and after the upgrade, because I had to keep the old PHP5 from Lenny since a lot of our PHP sites do not work well with PHP 5.3 and Squeeze has 5.3, Lenny had 5.2).

So today's learning was: always set PHP_FCGI_CHILDREN to 0 in your PHP wrapper script if you use FastCGI (mod_fcgid).

(P.S.: the article linked to this post tells you otherwise ... don't listen to it's bad advice Smile )