I have the laravel app running with Sail in EC2 Ubuntu AWS server.
I already have the command emails:send-weekly
that I have tested with both php artisan emails:send-weekly
and ./vendor/bin/sail emails:send-weekly
working as expected which is sending emails to all users in my app.
But when I add laravel schedule in app/Console/Kernel.php
:
class Kernel extends ConsoleKernel
{
protected function schedule(Schedule $schedule)
{
$schedule->command('emails:send-weekly')->weeklyOn(3, '13:00')->timezone('Asia/Jakarta');
}
protected function commands()
{
$this->load(__DIR__.'/Commands');
require base_path('routes/console.php');
}
}
The schedule is not working, I can see that the schedule list next due is counting down, but after the count down is over, I have not receive any email.
I have tried php artisan schedule:list
and ./vendor/bin/sail schedule:list
, both of them returning:
40 23 * * 3 php artisan emails:send-weekly . Next Due: 6 days from now.
Please tell me how to fix this? is there anything I need to set up to enable the schedule?
Turns out I forgot to set up my crontab. By opening crontab with 'crontab -e' and adding this code at the end of my crontab, the scheduler works as expected:
40 23 * * 3 cd laravel && php artisan emails:send-weekly >> /dev/null 2>&1