Open Task Scheduling file
Open yourProjectName/app/Console/Kernel.php
Config your schedule
Here is a schedule example
protected function schedule(Schedule $schedule) |
In my case, it’s to daily delete the expired orders
Add the Task Scheduling into crontab
sudo vim /etc/crontab
* * * * * apache cd /var/www/html/yourProjectName && php artisan schedule:run >> /dev/null 2>&1
- Here are the meaning of * * * * * in orders
- Minute(0-59)
- Hour(0-23)
- What date in a month(1-31)
- Month(1-12)
- What day in a week(0-6)
- apache
it represents the user. It’s important here, because if you don’t set it properly, when error occurs as you execute the schedule, the log owner will be the user you set here, which might have authority problem. If you also log other information in other place, and the whole project might not be able to work properly when the log file reject to be written. cd ray cd /var/www/html/yourProjectName
To where your project isphp artisan schedule:run >> /dev/null 2>&1
Run the Task Scheduling command in your Laravel project
- Here you go!
Comments