Note: change PHP version numbers to match your requirement. I have used 5.6 and 7.0
Changing php version for Aapche server
sudo a2dismod php5.6 ; sudo a2enmod php7.0 ; sudo service apache2 restart
Changing php version for command line usage
sudo ln -sfn /usr/bin/php7.0 /etc/alternatives/php
if it is not working still, you may need to disable the proxy_fcgi apache module and give it a try again
sudo a2dismod proxy_fcgi proxy; sudo service apache2 restart
Changing php version for Aapche server
sudo a2dismod php7.0 ; sudo a2enmod php5.6 ; sudo service apache2 restart
Changing php version for command line usage
sudo ln -sfn /usr/bin/php5.6 /etc/alternatives/php
if it is not working still, you may need to disable the proxy_fcgi apache module and give it a try again
sudo a2dismod proxy_fcgi proxy; sudo service apache2 restart