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
HTTPD=/usr/sbin/httpd.worker
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 http://www.apache.org/dist/httpd/mod_fcgid/mod_fcgid-2.3.6.tar.gz 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 </FilesMatch> 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
#!/bin/sh PHPRC=/etc/ export PHPRC export PHP_FCGI_MAX_REQUESTS=5000 export PHP_FCGI_CHILDREN=0 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:
- How Do I Configure Apache Server To Listen Multiple Ports ?
- Nginx 413 Request Entity Too Large
- How To Setup A LAMP Server On Centos 6.0
- How To Limit File Upload Size On Apache
- Display motherboard information on Linux
{ 3 comments… read them below or add one }
Hi,
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?
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.
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