Multiple php versions with 8.1 on Apache

Install multiple versions and switch between them

There are a number of posts on the web that will helpfully tell you how to install multiple versions of php that you can switch between when running on apache2.  This was all very simple until I installed php8.1.  Once installed, I was no longer able to switch between 8.1 and any other installed version.

It's all down to php-fpm.  It's just another thing that you need to take into consideration when switching between them.  Here's what you do.  Say you have php 5.6, 7.4 and 8.1 installed on your apache server and you want to swap to 7.4:

sudo a2dismod php5.6
sudo a2dismod php8.1
sudo a2enmod php7.4
sudo systemctl start php7.4-fpm
sudo systemctl enable php7.4-fpm
sudo a2disconf php8.1-fpm
sudo service apache2 restart

or you want to swap to 8.1:

sudo a2dismod php5.6
sudo a2dismod php7.4
sudo a2enmod php8.1
sudo systemctl start php8.1-fpm
sudo systemctl enable php8.1-fpm
sudo a2disconf php7.4-fpm
sudo service apache2 restart
That's it!
Merlin engine logo

The data revolution is here.

Merlin THE API builder for developers. Test it now

Get VIP access