Use different PHP version CLI executable for one command

You can use the alias command in your terminal to create a new command that runs a different version of PHP. For example, if you have PHP version 7.4 installed and want to create a new command that runs PHP version 8.0, you can use the following command:

alias php80='/usr/bin/php8.0'

Watch a course Learn object oriented PHP

This creates an alias called php80 that runs the PHP 8.0 executable located at /usr/bin/php8.0. To run a command using this PHP version, you can prefix the command with php80. For example:

php80 -v

This will display the version of PHP 8.0 that you are running.

Please note that the path to the PHP executable may be different on your system. You can check the path by running which php command and use that path in the alias command. Also, the above command assumes that php 8.0 is already installed in your system and this is just creating an alias for the command.