I am hosted with 1and1.com, and I have setup my files to be parsed with php5 using .htaccess
.
But that only works in apache, and not in command line, wh
I finally got this working. The problem was a few-fold.
First, the PHP being used was in /etc/bin instead of the MAMP version. I was able to change this and use the MAMP version instead.
Second, to use php via the CLI you have to make sure to use the FULL path to php and not just php itself. I.e. use /MAMP/bin/php/php5.3.x/php in your exec() call. This is now working for me.
You can check out my GIST here...https://gist.github.com/1861487
If you can execute PHP scripts directly in the shell like:
$ script.php
you can specify the binary that will execute the script in it's first line:
#!/usr/bin/php
<?php
That line is called shebang. The line might differ on your system, you need to know the full file system path of the PHP CLI binary you want to use for that script.
If you execute that file in the shell, the specified binary will be used. Same for cron.
If you execute that file via your webserver, PHP will drop that line silently.
See as well: Features: Using PHP from the command line
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)
This is another approach to force PHP from Command Line on 1and1.
Log in with ssh on your server and create a new file called .profile
in there you will write the following line
alias php='/usr/local/bin/php5'
Log back in with ssh and check php version with php -v
you should see
the version is now 5.
there must be two PHP directories and one of them should be the default one. try to find out php5's path from the root of your server and use full path at your cron job.
At least on Linux you can also specify the wanted PHP version in the first line of your script like so:
#!/usr/bin/php5.6
<?php
echo 'This is PHP version ' . phpversion() . "\n";
?>
Make your script executable and specify the cron job in the following way:
# Just runs the script, which itself cares for the right php version
* * * * * root "/path/to/script.php"