How to Switch php version in ubuntu. I have 3 php versions namely, php 5.6, php 7.0 and php 7.1. I will try to switch from php 5.6 to php 7.0 and vice versa. im using ubuntu 16.04


Apache

From php5.6 to php7.0.

sudo a2dismod php5.6
sudo a2enmod php7.0
sudo service apache2 restart



From php7.0 to php5.6

sudo a2dismod php7.0
sudo a2enmod php5.6
sudo service apache2 restart


and now try to check http: //localhost/info.php
Switch php version in ubuntu

Switch php version in ubuntu

Switch php version in ubuntu


why the php version on the command line has not changed?

Switch php version in ubuntu

The way is quite easy, enter to the command line:

sudo update-alternatives --set php /usr/bin/php-version


Example

PHP 5.6

sudo update-alternatives --set php /usr/bin/php5.6
and now,
php -v
Switch php version in ubuntu

PHP 7.0

sudo update-alternatives --set php /usr/bin/php7.0
and ,
php -v