Use crontab to execute php file

I try to put this in crontab :

50 19 * * * /usr/bin/php -f /var/www/html/phpscript.php 

this PHP script works well with php /var/www/html/phpscript.php...
I already follow many tutorials on the web, but nothing worked for me.
My crontab works because before this ligne, I have : 40 14,19,20,01 * * * /root/scripts/backup_bdd.sh which works well.

Does someone have a solution ?
Thank you !


Solution 1:

Jobs run through cron, crontab, aren't run in the same runtime environment that you have on your desktop. None of your PATH changes, or other environment variable settings are automatically propagated to your cron job. For example, there's no $DISPLAY, so GUI programs need special treatment (read man xhost).

One can set environment variables for all one's cron jobs in the crontab file Read man 5 crontab.

Look at the results of echo "=== set ===";set;echo "=== env ===";env | sort;echo "=== alias ===";alias in each of your environments.

Since the command part of the crontab line is, by default, interpreted by /bin/sh, which has a simpler syntax than /bin/bash, I recommend having command be a call to a bash script (executable, mounted, starts with #!/bin/bash) which sets up the environment, then calls the desired program.