What is mod_fastcgi?
mod_fastcgi is an Apache module for interfacing with CGI programs allowing a server to handle more requests at one time. It does this by keeping an instance of php running in the background. When apache receives the request it forwards it to FasctCGI. It can increase performance and reduce memory useage over mod_php. If you have not already done so, you will need to setup php-fpm for this to work. Please the following guide on how to do so Install PHP-FPM
Install mod_fastcgi
First get the required the required packages
wget -O /usr/src/mod_fastcgi-2.4.6.tar.gz https://github.com/txduncan/mod_fastcgi/blob/master/mod_fastcgi-2.4.6.tar.gz
Change to the download directory:
cd /usr/src
Uncompress the package:
tar xfvz mod_fastcgi-2.4.6.tar.gz
Copy the make file:
cp /usr/src/mod_fastcgi-2.4.6/Makefile.AP2 /usr/src/mod_fastcgi-2.4.6/Makefile
Make and install the package
make top_dir=/usr/lib64/httpd
make top_dir=/usr/lib64/httpd install
If the build directory differs from the standard apache build you will need to update top_dir to the parent directory of the build directory
Configure Apache to use mod_fastcgi
Edit /etc/httpd/conf/httpd.conf and add
LoadModule fastcgi_module lib/apache/mod_fastcgi.so
To make the entire Apache server to use php-fpm with mod_fastcgi:
Comment out any additional references to php in httpd.conf
# LoadModule php5_module modules/libphp5.so # AddType application/x-httpd-php .php
Edit /etc/httpd/conf/httpd.conf and add the following
LoadModule fastcgi_module modules/mod_fastcgi.so
Edit /etc/httpd/conf.d/fastcgi.conf and add the following
<IfModule mod_fastcgi.c> FastCGIExternalServer /usr/sbin/php-fpm -host 127.0.0.1:9000 AddHandler php-fastcgi .php Action php-fastcgi /usr/sbin/php-fpm.fcgi ScriptAlias /usr/sbin/php-fpm.fcgi /usr/sbin/php-fpm <Directory /usr/sbin> Options ExecCGI FollowSymLinks SetHandler fastcgi-script Order allow,deny Allow from all </Directory> </IfModule>
Be sure to update the path to the php-fpm binary in the above configuration, to find it do:
which php-fpm
Add a include in /etc/httpd/conf/httpd.conf
Include /etc/httpd/conf.d/fastcgi.conf
Restart Apache to load the new configuration:
service httpd restart
Once you have done that go ahead and create a test file in a Apache document root:
<?php phpinfo(); ?>
Visiting that page should show the PHP variables from the newly configured mod_fastcgi.