I’m going to outline the process of switching from Apache’s default installation of MPM Prefork to that of MPM Worker. I will also be covering the proper installation of FastCGI (mod_fcgid) to further improve your server performance. This guide is ideally intended for individuals running on low-memory VPS servers as memory consumption will likely be far lower with the Worker MPM because it spawns threads as opposed to forking child processes. If you’re intentionally reading this article, you’re probably aware of the performance benefits gained.
The worker MPM uses multiple child processes with many threads each. Each thread handles one connection at a time. Worker generally is a good choice for high-traffic servers because it has a smaller memory footprint than the prefork MPM.
I would not considering performing this on a production server as it entails taking down Apache in the process.
With all that being said, let’s begin… There are a few dependencies we need to ensure are installed. Let’s go grab those now:
For safety purposes, make a backup copy of any virtualhosts and your httpd.conf file. If you already have PHP installed on your machine, you’re going to need to disable it as well:
Make note of the fact the file
/etc/httpd/conf.d/php.conf handles loading the proper MPM module, whether it be prefork or worker. The line we are concerned with is:
Next, we’re looking to install the module libphp5-zts and mod_fcgid, so let’s try to find it first. You will most likely find an entry for
php-zts, a “Thread-safe PHP interpreter for use with the Apache HTTP Server”. Find and install this in addition to the FastCGI interface module by running:
This module creates an Apache configuration file in
/etc/httpd/conf.d/fcgid.conf. There are some configuration variables you may want to add to this file, it’s up to you:
Next, create the file
/etc/httpd/conf.d/php-fcgid.conf with the following contents:
The above script is the bread and butter. We first bind PHP scripts to the
php-fcgi handler, which in turn has an action assigned to delegate it to the file
/var/www/cgi-bin/phpfcgi. The alias is merely a tricky way of allowing you to override the value in a VHOST entry (if, for instance, you wanted to use a different PHP installation later on). The aliased location entry has an option for executing FastCGI.
This file we referenced,
/var/www/cgi-bin/phpfcgi, doesn’t actually exist. We want to symbolically link the file to the
php-cgi binary. Let’s do that:
Whew, almost there… Modify
/etc/sysconfig/httpd with your favorite editor; presumably nano, vi, vim, or emacs and uncomment the following line:
You’re up to the scariest part of the process, restarting your apache server. Use your favorite method. If the restart was successful, do a quick double-check of your log files:
Hopefully you’ll find lines like the following at the bottom of the log file: