How to run Multiple versions of PHP-FPM on Debian/Ubuntu?

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 on Debian/Ubuntu follow the below instructions step by step:
 

Apache2 & FastCGI module Installation:

Execute the following commands to install the latest version of Apache2 web server and FastCGI module:
 
sudo apt update
sudo apt install apache2 libapache2-mod-fcgid
 
Note: For earlier versions, the FastCGi package may be found with the name libapache2-mod-fastcgi
 
Restart the Apache webserver by running this command:
 
systemctl restart apache2.service
 

PHP Installation:

For the installation of PHP versions on Debian/Ubuntu, PPA Repository will be used. Execute the below commands to install multiple php versions:
 
sudo apt install python-software-properties
sudo add-apt-repository ppa:ondrej/php
apt update
sudo apt install php5.6 php5.6-fpm
sudo apt install 
sudo apt install php7.2 php7.2-fpm
 
After installing the above packages, php-fpm service will get started automatically. It can be verified by typing below command on terminal:
 
sudo systemctl status php7.0-fpm

Apache Configuration:

Now configure multiple PHP-FPM versions with apache server by running the commands below:
 
a2enmod actions fcgid alias proxy_fcgi
 
To configure the Apache VirtualHost to run with FPM/FastCGI use test virtual host and make a site in /etc/apache2/sites-available directory. Copy the virtual host file 000-default.conf as test123.conf and then open that file in text editor.
 
 cd /etc/apache2/sites-available/
 sudo cp 000-default.conf test123.conf
 sudo nano test123.conf
 
Add Below information in test123.conf file:
 
                - ServerName www.test123.com
                - ServerAlias tes123.com
                - DocumentRoot  = /var/www/html/
                <FilesMatch \.php$>
                     SetHandler "proxy:unix:/var/run/php/php7.0(version)-fpm.sock|fcgi://localhost/"
                </FilesMatch>
 

PHP-FPM Configuration:

User Group permissions are required to be set at PHP-FPM
 
sudo nano /etc/php/7.0/fpm/pool.d/www.conf
                - Unix user/group of processes
                - user = Debian
                - group = Debian
-Set permissions for unix socket
                - listen.owner = Debian
                - listen.group = Debian
 
After setting that, restart apache and PHP-FPM Services and enable some modules by running the below commands:
 
sudo a2enmod rewrite
sudo service apache2 restart
sudo service php7.0-fpm restart
 
Multiple PHP-FPM versions are now installed and configured on your Debain / Ubuntu 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.