Ubuntu Switch PHP Version

You have to change the PHP version for Command prompt (CMD) and for Apache browser like you run phpinfo() to check the version of PHP

Change PHP Version for CMD

You can run the following command from your CMS to change the PHP version in the Ubuntu system.

sudo update-alternatives --config php

This command will list all installed PHP versions in your system, just select the PHP version you wanted to enable for your localhost and hit enter.

Change PHP Version for Browser

Here we are showing examples of how to change the PHP version from 5.6 to 7.4 in Ubuntu.

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