Switch php versions on commandline ubuntu 16.04 Switch php versions on commandline ubuntu 16.04 apache apache

Switch php versions on commandline ubuntu 16.04


Interactive switching mode

sudo update-alternatives --config phpsudo update-alternatives --config pharsudo update-alternatives --config phar.phar

Manual Switching

From PHP 5.6 => PHP 7.1

Default PHP 5.6 is set on your system and you need to switch to PHP 7.1.

Apache:

$ sudo a2dismod php5.6$ sudo a2enmod php7.1$ sudo service apache2 restart

Command Line:

$ sudo update-alternatives --set php /usr/bin/php7.1$ sudo update-alternatives --set phar /usr/bin/phar7.1$ sudo update-alternatives --set phar.phar /usr/bin/phar.phar7.1

From PHP 7.1 => PHP 5.6

Default PHP 7.1 is set on your system and you need to switch to PHP 5.6.

Apache:

$ sudo a2dismod php7.1$ sudo a2enmod php5.6$ sudo service apache2 restart

Command Line:

$ sudo update-alternatives --set php /usr/bin/php5.6

Source


$ sudo update-alternatives --config php

should work for all ubuntu versions after 16.04 (18.04 and 20.04)

This is what you should see as a response

There are 4 choices for the alternative php (providing /usr/bin/php).  Selection    Path             Priority   Status------------------------------------------------------------* 0            /usr/bin/php7.2   72        auto mode  1            /usr/bin/php5.6   56        manual mode  2            /usr/bin/php7.0   70        manual mode  3            /usr/bin/php7.1   71        manual mode  4            /usr/bin/php7.2   72        manual modePress <enter> to keep the current choice[*], or type selection number:

Choose the appropriate version


To list all available versions and choose from them :

sudo update-alternatives --config php

Or do manually

sudo a2dismod php7.1 // disablesudo a2enmod php5.6  // enable