I have a PHP script which I am trying to run via cron. In cron I have

php /home/dir/dir/foo.php

When the command runs, the cron log says:

Status: 500 Internal Server Error

X-Powered-By: PHP/7.1.16

Content-type: text/html; charset=UTF-8

However, if I simply run php /home/dir/dir/foo.php from the command line, it runs just fine with no error.

I have another PHP script in the same directory which runs correctly via cron.

Other info: The script which isn't working is located outside the document root, creates a database connection, and connects to an API.

I don't have much experience with cron, so I probably set something up wrong, but I'm puzzled why the same command would work via CLI but not in cron.

  • You are executing php as cli in cron and get HTTP response? Could you please show whole crontab line? Jun 11, 2018 at 19:06
  • The whole crontab line is: 0,15,30,45 * * * * php /home/dir/dir/get_emails.php >/dev/null 2>&1
    – D Vogel
    Jun 11, 2018 at 19:08
  • And cron log says something? This part >/dev/null 2>&1 writes any output to /dev/null, so this should not be in any log. Are you sure, that this error comes from this script? Jun 11, 2018 at 19:11
  • Oh, sorry to be confusing. I rewrote the line to write to an error log, but I posted the version where it wen to /dev/null. Actually, I just figured out the answer myself. See answer below.
    – D Vogel
    Jun 11, 2018 at 19:12

1 Answer 1


I just figured out the answer. I changed "php" in the crontab entry to point instead to the PHP 7.1 path, and it's working now.

0,15,30,45 * * * * /opt/alt/php71/usr/bin/php /home/dir/dir/get_emails.php >/dev/null 2>&1

I would have thought that php in CLI would be the same version as php in cron, but apparently not.

  • It depends on how you have PHP installed and if you even have multiple versions of PHP on the system. If you have multiples, then the $PATH comes into play (and the various ini files, etc once the specific PHP binary has been found)
    – ivanivan
    Jun 12, 2018 at 0:03

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.