Install Apache with PHP & FastCGI on CentOS/RHEL
You can also visit the previous tutorial to configure Apache with multiple PHP versions using PHP-FPM/FastCGI on Ubuntu systems.
Apache Installation
Install Apache web server from the official repository. Launch terminal on your system or login with ssh to remote systems. Execute the following commands to install the latest available version of Apache web server and FastCGI module.
PHP Installation
For the installation of PHP versions, we use the PPA maintained here. Use the below couple of commands to add the PPA to your system. And install PHP 7.2 the latest version available on the day of writing this tutorial. Simply execute follows commands for the installation of PHP and PHP-FPM packages. After installing above packages php7.2-fpm service will automatically be started. You can make sure by typing below command on terminal.
Apache Configuration
Now enable few modules required for the configuration of multiple PHP versions with Apache. These modules are necessary to integrate PHP FPM and FastCGI with Apache server. Let’s configure the Apache VirtualHost to run with FPM/FastCGI. For this tutorial, we use default VirtualHost. Edit VirtualHost host configuration file in text editor. You can create new VirtualHost as per your requirements, so make sure to enable any new VirtualHost. Update the configuration as followings.
Save your changes to the configuration file and restart Apache to reload the changes.
Test Setup
Create a PHP script with phpinfo() function and place it to your server document root. Use below command to do it. Open a web browser access the info.php using server IP address (for default VirtualHost) for your configured domain in Apache VirtualHost.