Apache 2.2 by default has some settings which might not be optimal for hosting php-intensive websites. With some minor tweaks, we can keep the performance, but reduce the memory footprint of our webserver significantly.
Here's a short overview:
The timeout indicates how long a process will keep waiting for a request and respond to it. By default this is set to 300 seconds, which is a bit much for a normal content based website. It's best to lower this timeout to a more normal 20-30 seconds.
Timeout 300Timeout 30
This timeout setting indicates how long the server will wait for another process from the same client. This is one which is very dependent on how the server is used. For a website with a lot of longer articles, where users tend to read for quite some time, you can reduce this amount to 2-3 seconds. This will improve the memory consumption of your server, without harming the visitors. However, for average websites, where users don't spend too much time on each page, you can set it on a bit higher level, so you might catch a second request in the same process. I've set this at 15 seconds for this website.
KeepAliveTimeout 5KeepAliveTimeout 15
Prefork Multi-processing Method settings
By default, Apache 2.2 works with the prefork Multi-processing method. This is the way Apache handles multiple connections. The default settings have 5 listeners on startup, will always keep between 5 and 10 servers waiting for new connections, and will allow 150 concurrent client requests. This doesn't mean your site will only allow 150 visitors at a time, all these parameters will work together with each other (remember the Timeout settings). Of course, for the MaxClients settings, you'll need to keep in mind the available memory on your server. I've set it to 150, which corresponds to about 2.250 MB - don't set it that high, if your server can't support it. I've set the MaxRequestsPerChild to 2000, this means the process for a specific client will end after 2000 requests, which is good for php-heavy sites.
<ifmodule mpm_prefork_module=""> StartServers 5 MinSpareServers 5 MaxSpareServers 10 MaxClients 150
MaxRequestsPerChild 0MaxRequestsPerChild 2000 </ifmodule>
I'll be experimenting with the worker MPM a bit in the future, and will surely blog my findings on that. It seems the worker MPM has better resource management, and is a newer approach on the multi-process method.