mod_fcgid was introduced to be binary compatible with FastCGI, but with better control over spawning processes. It is a high performance alternative to mod_cgi or mod_cgid, which starts a sufficient number instances of the CGI program to handle concurrent requests, and these programs remain running to handle further incoming requests.

3. And install PHP CGI, and the a few other PHP components, if they are not already on your system.

# yum install php5-cgi php5-curl php5-gd php5-mysql

Configuring fcgid

To configure fcgid, you have to do two things:

1. Create a new file in /etc/apache2/conf.d/php-fcgid.conf and add the following in it:

AddHandler fcgid-script .fcgi .php
# Where to look for the php.ini file?
DefaultInitEnv PHPRC “/etc/php5/cgi”
# Maximum requests a process handles before it is terminated
MaxRequestsPerProcess 1000
# Maximum number of PHP processes
MaxProcessCount 10
# Number of seconds of idle time before a process is terminated
IPCCommTimeout 240
IdleTimeout 240
#Or use this if you use the file above
FCGIWrapper /usr/bin/php-cgi .php

For a large site with a server with more memory and CPUs we can use this:

AddHandler fcgid-script .fcgi .php
# Where to look for the php.ini file?
DefaultInitEnv PHPRC “/etc/php5/cgi”
# Where is the PHP executable
FCGIWrapper /usr/bin/php-cgi .php
# Maximum requests a process handles before it is terminated
MaxRequestsPerProcess 1500
# Maximum number of PHP processes.
MaxProcessCount 45
# Number of seconds of idle time before a process is terminated
IPCCommTimeout 240
IdleTimeout 240