I have a php script that I am trying to set up as a cron…
I am having a funny problem. I can run my command through the shell without problems, but when I put it in a cron, it does not work.
To troubleshoot, I asked it to email me and it sends an email with the following in the body:
Could not open input file: /home/USERNAME/script.php
(USERNAME is my user name)
At the command line, I have typed:
And it runs the script with the expected output.
My crontab is as follows:
*/3 * * * * /usr/local/php5/bin/php /home/USERNAME/script.php
It does run every 3 minutes as expected, but generates the email error every time. I have copied and pasted the command from my crontab to the commandline, and it runs without problems. I have copied and pasted my functioning command from the commandline to the crontab and that doesn’t work. Therefore I know there are no typos in the command in my crontab!
I tried adding a line to the top of my PHP file:
And it did not help.
I tried using $HOME/script.php instead of /home/USERNAME/script.php and that gave the same results - works on the command line, does not work in cron job.
I tried changing the permissions of the php file to 744 and to 755, neither worked.
I would prefer not to have the script in a web accessible folder, simply because it does not need to be accessed by anyone except me, so why would I introduce any security risks? So I suppose I could put it in a public folder and just do an html fetch in cron, but that seems like the wrong solution.
Any advice is appreciated!