By default, if you install PHP in ubuntu 18.04 PHP 7.2 will install, but many frameworks like Magento 2.2.6 does not support that version or Laravel. But if you change or install PHP to lower version still CLI version will not be changed. And that’s the framework which used CLI to does some functionality will not work.
So if you install other PHP version and then want to change the CLI PHP version, following things need to care.
sudo update-alternatives --set php /usr/bin/php7.1
Here I changed CLI PHP to 7.1, you can use yours.