ever since i switched to wordpress 2.5 (and 2.5.1) i was experiencing absurdly high CPU loads whenever i posted a new blog entry or changed a page — culminating in loads of 124+ yesterday, effectively bringing our server to a standstill!
not good. not good at all.
a ps ax | grep apache2 | wc -l revealed a rocking 104 apache2 processes running! yikes! all with about 21MB of memory usage (at least), no wonder the poor box was thrashing for dear life…
looking at what ubuntu had installed i found that (a) we had apache-prefork running and (b) switching to apache-worker1 would remove mod_php5 — which we need to have all the PHP scripts running (including this blog). hmmm.
some googling later it transpired that switching to thread-based apache was the right thing to do and also, that the fast CGI module mod_fcgid would be the solution to the disappearing php5 apache module.
here’s what i did: first install threaded apache
% apt-get install apache2-mpm-worker
then, install the fcgid module
% apt-get install libapache2-mod-fcgid
then, modify /etc/apache2/mods-available/fcgid.conf to read as follows:
<IfModule mod_fcgid.c>
AddHandler fcgid-script .php
FCGIWrapper /usr/local/sbin/php-fcgi .php
SocketPath /var/lib/apache2/fcgid/sock
SharememPath /var/lib/apache2/fcgid/shm
IPCConnectTimeout 60
</IfModule>
create /usr/local/sbin/php-fcgi .php with the following content:
#!/bin/sh
PHPRC="/etc/php5/apache2"
export PHPRC
PHP_FCGI_CHILDREN=1
export PHP_FCGI_CHILDREN
PHP_FCGI_MAX_REQUESTS=5000
export PHP_FCGI_MAX_REQUESTS
exec /usr/bin/php5-cgi
now, all that’s left to do, is ensure that for each virtual host you have ExecCGI enabled:
<Directory /var/www/xyzzyxyzzy.net/>
Options ExecCGI Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
Allow from all
</Directory>
restart your apache and we are back in business — on my box the load is now back in sane regions: instead of 124+ we are back at 0.52 for posting a blog entry (at most)!
-
the thread based apache. ↩

Hi, I followed your instructions – thanks! – and all seems to be working fine as before, but how do I check whether this threaded thing is actually working? Thanks in advance
comment by Vito Botta — May 7, 2009 @ 12:19
while it does run smoothly most of the time, i’ve since encountered this situation again a couple of times. currently i’m contemplating switching to lighttpd…
sorry about getting your hopes up…
comment by DrScofield — May 7, 2009 @ 22:47
So how did you keep apt/dpkg from removing php5 and all the stuff it’s a dependency for?
comment by Dr. Kenneth Noisewater — June 10, 2009 @ 17:54
hmm… i think i installed those php5 packages that i needed afterwards — though, with a more recent version of ubuntu the dependencies might have changed.
in any case, see my earlier comment about this possibly not helping much
comment by DrScofield — June 11, 2009 @ 08:14