Laravel工匠Cron任务在Ubuntu上不起作用 [英] Laravel artisan cron task not working on ubuntu
问题描述
在过去的5个小时中,我一直在完成我认为很简单的任务,为Laravel启用了cron功能.我在Amazon EC2 Ubuntu LAPP堆栈服务器上运行Laravel 5.1.
I have been pulling my hair out for the past 5 hours over what I thought would be a simple task, enabling the cron feature for Laravel. I am running Laravel 5.1 on an Amazon EC2 Ubuntu LAPP stack server.
我已使用命令将cron任务添加到cron作业列表中
I have added the cron task to the cron jobs list using the command
sudo crontab -e
然后我添加了laravel文档中列出的命令
Then I have added the command listed in the laravel documentation
* * * * * php /home/bitnami/htdocs/project/app/artisan schedule:run >> /dev/null 2>&1
我确保cron正在运行,并且如果我运行,我可以看到任务正在运行
I have made sure that cron is running and I can see that the task is running if I run
sudo grep -i cron /var/log/syslog|tail -3
返回哪个
Mar 4 15:36:01 ip-172-31-7-174 CRON[15120]: (root) CMD (php /home/bitnami/htdocs/project/app/artisan schedule:run >> /dev/null 2>&1)
Mar 4 15:37:01 ip-172-31-7-174 CRON[15123]: (root) CMD (php /home/bitnami/htdocs/project/app/artisan schedule:run >> /dev/null 2>&1)
Mar 4 15:38:01 ip-172-31-7-174 CRON[15125]: (root) CMD (php /home/bitnami/htdocs/project/app/artisan schedule:run >> /dev/null 2>&1)
我已经通过从命令行运行命令来测试路径中没有任何错别字,并且可以正常工作
I have tested that the path has not got any typos in it by running the command from the command line and it works properly
php /home/bitnami/htdocs/project/app/artisan schedule:run
我还添加了此cron任务只是为了确认cron确实正在运行
Also I have added this cron task just to confirm that cron is actualy running
* * * * * echo "Cron" > /home/bitnami/htdocs/project/app/artisan/file.txt
我还通过执行以下操作来确保文件是可执行文件,但这也不能解决问题
I have also made sure the file is executable by doing the following but this has not fixed the issue either
chmod 755 artisan
chmod 777 artisan (I am aware this is dangerous)
chmod +x artisan (Suggested on fourms)
有人对我在这里出错的任何建议吗?
Does anyone have any suggestions where I'm going wrong here.
推荐答案
我已经遇到了这种情况并找到了解决方案.这是因为bitnami中的未知原因,因此cron无法识别php命令.我使用此命令使其正常工作:
I've experienced this and found a solution. It's because of unknown reason in bitnami, so that php command not recognized by cron. I used this command to make it working :
* * * * * /path/to/php/bin/php /home/bitnami/htdocs/project/app/artisan schedule:run 1>> /dev/null 2>&1
这篇关于Laravel工匠Cron任务在Ubuntu上不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!