I had the same problem when I was handling multiple projects. I referred this article But it was like every time I need to switch the versions if need but this gives the flexibility for cli and web separately.
Moving From php5.6 to php7.0
For Apache, we can use the command as:
sudo a2dismod php5.6 ; sudo a2enmod php7.0 ; sudo service apache2 restart
For CLI, we can use the command as:
sudo update-alternatives --set php /usr/bin/php7.0
Moving From php7.0 to php5.6
For Apache, we can use the command as:
sudo a2dismod php7.0 ; sudo a2enmod php5.6 ; sudo service apache2 restart
For CLI, we can use the command as:
sudo update-alternatives --set php /usr/bin/php5.6
Source: server – How to have two versions of PHP installed and switch easily between them? – Ask Ubuntu
server – How to have two versions of PHP installed and switch easily between them? was last modified: July 24th, 2018 by