How can I force PHP Version for Command Line?

If both are installed, all you need to do is run the script using the relevant PHP binary.

So for example:

 // Runs using the PHP binary located at /usr/bin/php
 * * * * * root /usr/bin/php -n "/path/to/script.php"

or

 // Runs using the PHP binary located at /var/php5
 * * * * * root /var/php5 -n "/path/to/script.php"

All you need to know is the full file system path of the PHP CLI binaries, and call the relevant one to run your code.


In accordance to https://community.1and1.com/using-php-composer-at-1and1/, create .profile in your root projet and add the line :

alias php='/usr/bin/php5.5-cli'

It works for me. Log out and log back in SSH and do :

php -v

Result :

PHP 5.5.32 (cli) (built: Feb 15 2016 16:13:44)