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

fast-cgi

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
 
#!/bin/bash
PHPRC="/etc/php.ini"
PHP_FCGI_CHILDREN=4
PHP_FCGI_MAX_REQUESTS=1000
export PHPRC
export PHP_FCGI_CHILDREN
export PHP_FCGI_MAX_REQUESTS
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 .

ServerName www.techtransit.org
    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.

<?php
phpinfo();
?>

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.

https://www.techtransit.org/info.php

cgi_snap

By Sachin G

I am a professional freelance contributor and founder of tech transit. Love to write and lover of education, culture, and community. I have been using it, setting, supporting, and maintaining it since 2009.Linux rocks! Sachin G Follow me on LinkedIn and x formerly twitter