DN0300
DN0300

Reputation: 876

Cron Won't Execute PHP

I have been trying to execute PHP script using cronjob, but I can't get it to work. I've tried every solution I could find with no luck. Following is the process I am using:

sudo crontab -e

*/1 * * * * /user/bin/php /var/cron.php >> /var/log/cron.txt 2>&1

PHP script works when manually executed: (cron.php)

<?php 
 file_put_contents("output.txt", "Works");
?>

When I run a script which is not php it works, for example, the following script runs every 1 minute and works

*/1 * * * * touch /var/cron.txt >> /var/log/cron.txt 2>&1

If any of you can point out where I am going wrong I would really appreciate it.

Upvotes: 0

Views: 94

Answers (1)

DN0300
DN0300

Reputation: 876

As Barmar mentioned in a comment, I was missing the absolute path for the output file in my script. Once I added that to my script file got created where I was expecting it to.

Upvotes: 1

Related Questions