There are a few cases where you might want to keep your old version of PHP for compatibility, or preference, but also need a newer or cutting edge version for a particular app (eg. Nextcloud [howto/whyto post to follow]).
Fear not – this CAN be done. Here’s my marginally modified version of the post from here
xxxxxxxxxx
sudo apt install -y ca-certificates apt-transport-https
wget -q https://packages.sury.org/php/apt.gpg -O- \
| sudo apt-key add -
echo "deb https://packages.sury.org/php/ stretch main" \
| sudo tee /etc/apt/sources.list.d/php.list
#
sudo apt update
sudo apt upgrade
#
# php5.6 + modules
sudo apt install --reinstall -y php5.6-fpm php5.6 \
php5.6-dev php5.6-mbstring php5.6-mysql php5.6-zip \
php5.6-gd php5.6-xml php5.6-curl php5.6-intl \
php5.6-json php5.6-opcache php5.6-readline \
php5.6-xmlrpc php5.6-common php5.6-cli php5.6-mcrypt
#
# php7.x + modules
sudo apt install --reinstall -y php7.3-fpm php7.3 \
php7.3-dev php7.3-mbstring php7.3-mysql php7.3-zip \
php7.3-gd php7.3-xml php7.3-curl php7.3-intl \
php7.3-json php7.3-opcache php7.3-readline \
php7.3-xmlrpc php7.3-common php7.3-cli
#Seems there is no phpX.X-mcrypt since 7.2
#
# check if they're up and running
sudo systemctl status php5.6-fpm
sudo systemctl status php7.3-fpm
#
# Apache Installation
sudo systemctl stop nginx
# If this is running, apache2 won't install properly
sudo apt install --reinstall -y apache2 libapache2-mod-fcgid
#
# 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.
sudo a2enmod actions fcgid alias proxy_fcgi setenvif
sudo a2enconf php5.6-fpm php7.3-fpm
#
# to change version specific PHP behaviour....
# eg. opcache (in php.ini), you need to RESTART (NOT reload)
# the php-fpm module after you've edited the ini file
nano /etc/php/7.3/apache2/php.ini
/etc/init.d/php7.3-fpm restart
sudo systemctl restart apache2.service
#
check if your changes worked using something like this …
php -i | grep "opcache\|YOUR_MOD_NAME"
Once this is done and running, create a test VirtualHost …
xxxxxxxxxx
sudo nano /etc/apache2/sites-available/php56.domain.info.conf
#Add the following content.
# Make sure to use correct ServerName and directory path
# according to your setup.
# This website is configured to work with PHP 5.6.
ServerName php56.domain.info
ServerAlias 192.168.1.111 #optional
DirectoryIndex index.html index.php
DocumentRoot /var/www/html/php56.domain.info
Options -Indexes +FollowSymLinks +MultiViews
AllowOverride All
Require all granted
# Apache 2.4.10+ can proxy to unix socket
SetHandler "proxy:unix:/var/run/php/php5.6-fpm.sock|fcgi://localhost/"
This example is set up for PHP 5.6.
If you wanted to use 7.3, you would change this line in the config, and then restart apache2
SetHandler “proxy:unix:/var/run/php/php7.3-fpm.sock|fcgi://localhost/”
Wow that was unusual. I just wrote an extremely long comment but after I clicked submit
my comment didn’t appear. Grrrr… well I’m not writing all that over again. Anyway, just wanted to say wonderful blog!