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.
Best Answer
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.
I would have thought that php in CLI would be the same version as php in cron, but apparently not.