How to run Multiple versions of PHP-FPM on CentOS?

PHP-FPM (FastCGI Process Manager) is an alternative implementation of PHP FastCGI that allows a website to handle high loads. It provides some additional features like adaptive process spawning which is useful for websites. To install PHP-FPM Multiple versions on CentOS follow the below instructions step by step:

Install Repositories

There are two repositories required to be installed. The first one is EPEL which can be installed by running this command:
The second one is REMI which can be installed by running this command:

Install yum-utils Package

Now to install yum-utils package by running this command:
sudo yum install yum-utils

Apache and PHP-FPM FastCGi installation:

To install the latest version of Apache web server along with default PHP version and FastCGi module, run this command on CentOS machine
 yum install httpd php php-cli mod_fcgid
In next step, create a new file with name php.fastcgi at this path /home/www/cgi-bin/php.fastcgi and then add the below content to this file by running the below commands:
# nano /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
Now, to install multiple versions of PHP run the below commands.
sudo yum-config-manager --disable remi-php54
sudo yum-config-manager --enable remi-php73
sudo yum-config-manager --enable remi-php71
sudo yum-config-manager --enable remi-php72
Also install PHP 7.3 along with all necessary modules:
sudo yum -y install php php-fpm php-mysqlnd php-zip php-devel php-gd php-mcrypt php-mbstring php-curl php-xml php-pear php-bcmath php-json php-pdo php-pecl-apcu php-pecl-apcu-devel
To verify the installed version of PHP, run this:
php -v

Configure PHP-FPM:

Open php.ini file:
sudo nano /etc/php.ini
and add this line to the configuration file and then Save and close the file.
Next, open www.conf file:
sudo nano /etc/php-fpm.d/www.conf
Now find user and group and change their values to centos.
user = centos
group = centos
Now find listen.owner and and change their values to centos.
listen.owner = centos = centos
Last, find listen parameter and change the line to:
listen = /var/run/php-fpm/php-fpm.sock
Save & close the file and start the PHP processor by typing:
sudo systemctl start php-fpm
Enable php-fpm to start on boot:
sudo systemctl enable php-fpm
Here are some useful commands for PHP_FPM service:
sudo systemctl stop php-fpm
sudo systemctl restart php-fpm
sudo systemctl status php-fpm
Multiple PHP-FPM versions are now installed and configured on CentOS machines. To test, you can create a test.php file in your DocumentRoot with content below and access it via your web browser:
<?php phpinfo(); ?>
You will be able to see FPM/FastCGI as Server API in PHP configuration.
Disclaimer: The instructions mentioned above are for information purpose only. Follow these at your own risk and discretion as Hosting Controller Inc. will not be responsible for any data loss or issue which may occur while following these instructions.