What is the difference between specifying "/usr/bin/php" and just using "php" when setting up a PHP script to run in my crontab? I would tend to just use "php" rather than the full path.

30 16 * * *  php /var/www/vhosts/dev_crm/cron/picco.php >> /home/crmpicco/cron-picco.log 2>&1


30 16 * * *  /usr/bin/php /var/www/vhosts/dev_crm/cron/picco.php >> /home/crmpicco/cron-picco.log 2>&1



Who runs this crontab ?

It may be run by a different user, who does not have /usr/bin in his $PATH, or it may run with a modified environment, equally without /usr/bin in its $PATH.

If in doubt, specify the full path.

  • The crontab is owned and run by the "crmpicco" user. I can confirm that the cron jobs appear to run ok using "php", however how can I check that /usr/bin is in this user's $PATH? – crmpicco Apr 2 '12 at 15:11

The difference is that the first crontab will not work :)

The reason is that the user executing the crontabs don't have its PATH variable populated to limit impact of involuntary mistakes.

You can declare the variable again in front of the command if needed:

30 16 * * *  PATH=/usr/bin/ php /var/www/vhosts/dev_crm/cron/picco.php >> /home/crmpicco/cron-picco.log 2>&1
  • That's more typing than just using the whole path! :P – adaptr Apr 2 '12 at 15:18
  • @Shadok Both crontabs work, I can confirm that. I assume that means that I have /usr/bin/php "mapped" to php somewhere. – crmpicco Apr 2 '12 at 15:45
  • FYI "somewhere" is in the PATH variable of the user executing the crontab :) Try to "su user" and then "echo $PATH" and you should the path where your php binary resides in the list. – Shadok May 10 '12 at 16:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.