Apache Linux OS PHP

Authored by Corey Ballou


Switching Apache from Prefork to Worker MPM in RHEL / CentOS 5.x / Fedora 13

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:

Author: Corey Ballou

Corey Ballou is the CEO of Whether you're a student, young professional, entrepreneur, startup, or small business, you can be up and online fast with your own custom domain, email, and webpage on POP. Corey is a professional PHP developer by trade, specializing in custom web applications development for startups, small businesses, and agencies. Follow Corey on Twitter @cballou.

  • cs

    this is lame because the php-zts package doesnt even include mysql support.
    I followed your tut, only to find that I had to start all over since mysql support is essential.
    you forgot to mention this…
    now, I have to compile php from source.

    • sanjith

      any solution for mysql with php on worker MPM

  • Silver Moon

    is php-zts necessary ?

    • James Morgan

      I appreciate that this is 2 years after you commented but for the benefit of anybody else reading. Yes. Without it you get

      msg: httpd.worker: Syntax error on line 221 of /etc/httpd/conf/httpd.conf: Syntax error on line 9 of /etc/httpd/conf.d/php.conf: Cannot load /etc/httpd/modules/ into server: /etc/httpd/modules/ cannot open shared object file: No such file or directory