Enable two versions of PHP with Apache on Centos 7

I had Apache server running with PHP 5.6 using mod_php but needed PHP 7.3 for a particular application.

In order to have both installed at the same time I wanted to continue to use PHP 5.6 for all sites but only enable PHP 7.3 for a particular VirtualHost. To do this I continued to use mod_php for v5.6 and installed PHP-FPM for v7.3.

With the “remi” repo activated install “php73” (you should also install whatever other PHP 7.3 extensions you want):

yum install php73-php php73-php-fpm

Once installed you need to start the FPM server:

systemctl start php73-php-fpm
systemctl enable php73-php-fpm

In the configuration file for the VirtualHost that you wish to use v7.3

<VirtualHost>
  ......
  <FilesMatch \.php$>
  SetHandler "proxy:fcgi://127.0.0.1:9000"
  </FilesMatch>
<VirtualHost>

After updating the configuration file you’ll need to restart Apache:

systemctl restart httpd

Finally, if you need to run v7.3 of PHP from the command line enable it for the current session with:

scl enable php73 bash

or to enable for all sessions create an autoload file for bash in /etc/profile.d/php73.sh with the following content:

#!/bin/bash
source /opt/remi/php73/enable
export X_SCLS="`scl enable php73 'echo $X_SCLS'`"