Posted 2019-07-29 with tags Ubuntu 16.04, PHP, PHP 7.0, PHP 7.1

Apparently there is no official PHP 7.1 available for Ubuntu 16.04, but according to this askubuntu.com post there is a reasonably trustworthy PPA: ppa:ondrej/php which allows the installation of PHP 7.1 (and multiple other versions).

sudo add-apt-repository ppa:ondrej/php
sudo add-apt-repository ppa:ondrej/apache2
sudo apt update

After install you can check the currently enabled version and switch to a different version with the following:

update-alternatives --config php
There are 2 choices for the alternative php (providing /usr/bin/php).

  Selection    Path             Priority   Status
  ------------------------------------------------------------
  * 0            /usr/bin/php7.3   73        auto mode
    1            /usr/bin/php7.0   70        manual mode
    2            /usr/bin/php7.3   73        manual mode

To switch the version of PHP used by apache:

$ sudo a2dismod php7.0
$ sudo a2enmod php7.1
$ sudo systemctl restart apache2

Ensure all necessary PHP modules are installed for each version of PHP you plan to use.