Switch between PHP versions on Ubuntu

Multiple PHP versions can be installed next to each other.

Easily switch between them with a2dismod and a2enmod.

For instance; to disable PHP 7.2 and enable 7.1:

sudo a2dismod php7.2

sudo a2enmod php7.1

sudo /etc/init.d/apache2 restart

When you need to install PHP7.1 but can’t, add this repo:
sudo add-apt-repository ppa:ondrej/php
sudo apt-get update

Then you can go ahead and install what you need:
sudo apt install php7.1
sudo apt install php7.1-cli php7.1-common php7.1-json php7.1-opcache php7.1-mysql php7.1-mbstring php7.1-mcrypt php7.1-zip

Leave a Reply