Install and Configure FastCGI on CentOS/RHEL

Install and Configure FastCGI and PHP on Centos/RHEL

Step 1: Install PHP and FastCGI

We are assuming that apache or web server is installed on linux box (CenOS/RHEL) .Use below command to install latest available php and FastCGI apache module

 # yum install php php-cli mod_fastcgi


Step 2: Configuration of FastCGI

Now we have install apache FastCGI Module and In next steps we need to create a file with name
/home/www/cgi-bin/php.fastcgi file and should be added content to this file.

# vim /home/www/cgi-bin/php.fastcgi
export PHPRC
exec /usr/bin/php-cgi

php.fastcgi script should be runnable by apache server , so we need to setup permission on the file like below.

# chown apache:apache /home/www/cgi-bin/php.fastcgi
# chmod +x /home/www/cgi-bin/php.fastcgi

Step 3: Configure the VirtualHost with FastCGI

Now  create a VirtualHost in our apache configuration file with FastCGI configuration .

    ServerAdmin [email protected]
    DocumentRoot /home/www/techtransit/
    ScriptAlias /cgi-bin/ "/home/www/cgi-bin/"
    <Directory "/home/www/techtransit/">
            Options +Indexes FollowSymLinks +ExecCGI
            AddHandler php5-fastcgi .php
            Action php5-fastcgi /cgi-bin/php.fastcgi
            AllowOverride All
            Order allow,deny
            Allow from All
    </Directory >

Step 6: Restart Apache and Test Setup
For reading the configuration file restart the web server.Below is the command to restart the web server.

service httpd restart

Create a file in your document root /var/www/html/info.php and add following content to check detailed php information.


Access your file info.php through using ip address for domain name . This will reflect the current configuration of PHP in your system. Look the value of Server API option, if you get this value CGI/FastCGI, it means server is properly configured to use FastCGI.