Install Apache with PHP-FPM/FastCGI on Ubuntu

This tutorial will help you to set up Apache webserver with PHP and FastCGI on RedHat based systems.

Step 1 – Prerequsitis

Fast of all, enable REMI and EPEL yum repositories on your system. These repositories provide the lastest packages for RedHat based systems.

Enable EPEL and REMI Repository

Step 2 – Install Apache2

Apache2 packages are available with the name HTTPD for Redhat based systems. You can use the following commands to install the latest available Apache2 (HTTPD) packages in configured repositories on your system.

Step 3 – Install PHP and FastCGI

After installing the Apache web server, let’s install PHP and FastCGI Apache module on your system. You can install any version of the required PHP or simply use the following command to install available PHP packages. This tutorial doesn’t include installing PHP modules, So you can also install required PHP modules.

Step 4 – Disable Default PHP Handler

Before using PHP/FastCGI handler, you have to disable the default PHP handler on your system. Edit PHP configuration file for Apache (/etc/httpd/conf.d/php.conf) in your favorite text editor and comment following lines showing in below screenshot by adding the hash (#) sign at the start of the lines.

Step 5 – Setup FastCGI Handler

At this point we have successfully installed Apache FastCGI Module. Now nagigate to /var/www/cgi-bin directory, If not exists create directory. Then create a php.fastcgi file and add the following content to this file. Also make sure the php.ini file and php-cgi exist on your system. Change permissions of php.fastcgi script to make it executable by Apache server.

Step 6 – Setup VirtualHost with FastCGI

Finally, create a VirtualHost in our Apache configuration file with FastCGI support. VirtualHosts are used to configure multiple sites with a single IP. Below configuration will allow siting svr1.tecadmin.net with any system IP on port 80.

Step 7 – Restart Apache and Test Setup

At this point, you have completed the Apache configuration with FastCGI support. Let’s restart the Apache server using the following command. Now create a file in your document root /var/www/html/info.php and add following content to check detailed php information.

Access your Apache server using an IP address for domain name followed by php.info file in your web browser like below. This will show 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.

How To Setup Apache with PHP FastCGI on CentOS RHEL 7 6 - 1How To Setup Apache with PHP FastCGI on CentOS RHEL 7 6 - 67