Apache’s prefork MPM is a very heavy memory eater. Thirty instances together with PostgreSQL can consume more then 1.5GB of memory. I have already managed the PostgreSQL to become modest. Now the Apache is the target.
I need to decrease the memory consumption or decrease the processes count. How about worker MPM? It uses more threads than processes.
I’m running a lot’s of applications mostly with mod-python. But I need PHP for applications like phpmyadmin and Horde. Biggest issue is how to replace mod-php which depends on the prefork MPM because it is not thread-safe. Solution can be found in FastCGI. Let’s try it:
- get rid of apache2-mpm-prefork and libapache2-mod-php5 and install apache2-mpm-worker and php5-cgi.
- Configure Apache. You can find a lots of examples on the internet how to simply configure PHP+FastCGI. For eager beavers a quick tour:
- enable Apache’s action and fastcgi modules.
- put following lines in Apache’s configuration:
AddType application/x-httpd-php .php AddHandler php5-fastcgi .php Action php5-fastcgi /cgi-bin/php5
Voila! Simple PHP scripts works!
But first problem arises. I can’t get into phpmyadmin. Firefox wants to download the page as PHTML. Solution is to clear the Firefox’s cache.
Another and harder problem comes. I have some .htaccess files with PHP directives (like php_flag). Now they doesn’t work because they worked only with mod-php. And generaly it will not work with FastCGI anyway. Some suggestions can be found e.g. in H-Sphere forum. Well you have to go around 🙂