简体   繁体   中英

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM