As you probably know it’s possible to install multiple versions of PHP on one server. For web servers, simply define which PHP version you want to use in your server’s configuration file. But how to do it for PHP cli?
First, check default PHP cli version with:
# php -v
Then if, for example, the default version for PHP command is 5.6 you can change to version 7.4 using update-alternatives command like this:
# update-alternatives --set php /usr/bin/php7.4
Of course, you can also directly call php7.4 command. The same way you can set other supporting commands like phpize to the required version:
# update-alternatives --set phpize /usr/bin/phpize7.4
Don’t forget sudo in front of the command if you’re not logged as the root user (which is highly not recommended in the production environment).