How to switch between 2 PHP versions?

May be you might have an old PHP version like PHP 5.6 in your system and you installed PHP 7.2 too so thats multiple PHP in your machine. There are some applications which were developed when older PHP 5.6 was latest version, they are still live and you working on those applications, You might be working on Laravel simultaneously but Laravel requires PHP 7+ to get started. Getting the picture ?

In that case you can switch between the PHP versions to suit your requirements.

Switch From PHP 5.6 => PHP 7.2

Apache:-

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

Command Line:-

sudo update-alternatives --set php /usr/bin/php7.2sudo update-alternatives --set phar /usr/bin/phar7.2sudo update-alternatives --set phar.phar /usr/bin/phar.phar7.2sudo update-alternatives --set phpize /usr/bin/phpize7.2sudo update-alternatives --set php-config /usr/bin/php-config7.2

And vice-versa, Switch From PHP 7.2 => PHP 5.6

Apache:-

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

Command Line:-

sudo update-alternatives --set php /usr/bin/php5.6sudo update-alternatives --set phar /usr/bin/phar5.6sudo update-alternatives --set phar.phar /usr/bin/phar.phar5.6 sudo update-alternatives --set phpize /usr/bin/phpize5.6sudo update-alternatives --set php-config /usr/bin/php-config5.6