在CentOS上设置Laravel定时任务,你需要使用系统的Cron服务。以下是设置步骤:
打开终端。
输入以下命令来编辑crontab文件:
crontab -e
* * * * * cd /path-to-your-project && php artisan schedule:run >> /dev/null 2>&1
请将/path-to-your-project
替换为你的Laravel项目的实际路径。
这个Cron表达式的意思是每分钟运行一次php artisan schedule:run
命令,该命令会检查是否有待执行的定时任务。
保存并退出crontab文件。
为了确保Cron服务正在运行,请输入以下命令:
sudo systemctl status crond
如果Cron服务没有运行,请使用以下命令启动它:
sudo systemctl start crond
现在,你的Laravel定时任务已经在CentOS上设置好了。你可以根据需要调整Cron表达式以更改任务的执行频率。