Installing Apache With Worker MPM And PHP-FastCGI

by lifeLinux on August 28, 2011

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. This guide provides the process of switching from Apache’s default installation of MPM Prefork to that of MPM Worker and i will also be covering the proper installation of FastCGI (mod_fcgid) to further improve your server performance.

Install Apache & Switching Apache to Worker MPM mode

To install apache on CentOS, type the following command as root

# yum install httpd

If you want to run Apache by default when the system boots, type the following command

# chkconfig httpd --level 2345 on

To start Apache for the first time, type the following command

# /etc/init.d/httpd start

To switch Apache to Worker MPM mode edit /etc/sysconfig/httpd

# vi /etc/sysconfig/httpd

Uncomment the following line


Install PHP & mod_fcgid

To install PHP 5.3 on CentOS, type the following command

# yum install php53

Apache run mod_php by default, to disable mod_php, type the following command

# mv /etc/httpd/conf.d/php.conf /etc/httpd/conf.d/php.conf.bak

To install mod_fcgid, the first you need to ensure httpd-devel package installed, enter

# yum install httpd-devel

Download & Extract mod_fcgid

# wget
tar zxvf mod_fcgid-2.3.6.tar.gz
cd mod_fcgid-2.3.6

To compile mod_fcgid, type the following command

# ./configure.apxs
# make
# make install

The module will be automatically installed and specified in the configuration file of the Apache. The next step create config for mod_fcgi, enter

# vi /etc/httpd/conf.d/mod_fcgid.conf

Add the following content

AddHandler php-fcgi
<FilesMatch \.php$>
Options +ExecCGI
AddHandler php-fcgi .php
FCGIWrapper /var/www/cgi-bin/php-fcgi .php
AddType text/html .php
DirectoryIndex index.php

Create php-fcgi script in cgi-bin, enter

# vi /var/www/cgi-bin/php-fcgi

Add the following content

export PHPRC
exec /usr/bin/php-cgi

Make file executable

# chmod +x /var/www/cgi-bin/php-fcgi

I would recommend that you specify the line below in /etc/php.ini cgi.fix_pathinfo = 1, enter

# echo "cgi.fix_pathinfo = 1" >> /etc/php.ini

Final, restart Apache with the following command

# /etc/init.d/httpd restart

Related Posts:

{ 3 comments… read them below or add one }

Steve March 1, 2012 at 11:11 pm


I am trying to get PHP working with httpd.worker on RHEL 5.x without much success. Following your instructions I have a small problem with the .conf file. This 1st line “AddHandler php-fcgi” is erroring saying it needs another parameter. Would this be the sam as the 4th line?


Ganpat April 4, 2012 at 12:11 pm

I am trying to install fast cgi on centos 64 bit with same steps but it didn’t work. It shows php source code on browser.


Peter November 3, 2012 at 2:15 am

Try putting:

AddHandler php5-fastcgi .php
Action php5-fastcgi /cgi-bin/php-fcgi
Options -Indexes FollowSymLinks +ExecCGI

for the content in /etc/httpd/conf.d/mod_fcgid.conf instead of what was listed. Worked like a charm


Previous post:

Next post: