Problem:
I have a Laravel 5.4 artisan task that I need to run via cron - but it is not being completed despite the Command and Scheduler being (apparently) set-up correctly.
Is this a Laravel, php, apache, linux or crontab issue ? What's the best way to diagnose ?
Background
On default (amazon AMI) EC2 instance, the artisan command is defined correctly and runs perfectly from the project directory (which is /var/www/html/myproject/
) when called via:
php artisan mycommand:option1
I've added this to a schedule into app/Console/Kernel.php
which looks like this:
protected function schedule(Schedule $schedule)
{
Log::info('schedule:run');
$schedule ->command('mycommand:option1')
->dailyAt('07:00')
->emailOutputTo('[email protected]');
$schedule ->command('mycommand:option2')
->dailyAt('07:15')
->emailOutputTo('[email protected]');
}
Added the following cron command for apache
via sudo crontab -u apache -e
:
* * * * * php /var/www/html/myproject/artisan schedule:run >> /dev/null 2>&1
To ensure it's not a permissions issue I also added the same command for the following users :
ec2-user
viacrontab -e
root
viasudo crontab -e
System Output
from sudo tail -f /var/log/cron
:
Apr 11 19:17:01 ip-10-0-0-42 CROND[17968]: (root) CMD (php /var/www/html/myproject/artisan schedule:run >> /dev/null 2>&1)
Apr 11 19:17:01 ip-10-0-0-42 CROND[17969]: (ec2-user) CMD (php /var/www/html/myproject/artisan schedule:run >> /dev/null 2>&1)
Apr 11 19:17:01 ip-10-0-0-42 CROND[17970]: (apache) CMD (php /var/www/html/myproject/artisan schedule:run >> /dev/null 2>&1)
Apr 11 19:18:01 ip-10-0-0-42 CROND[17980]: (ec2-user) CMD (php /var/www/html/myproject/artisan schedule:run >> /dev/null 2>&1)
Apr 11 19:18:01 ip-10-0-0-42 CROND[17981]: (apache) CMD (php /var/www/html/myproject/artisan schedule:run >> /dev/null 2>&1)
Apr 11 19:18:01 ip-10-0-0-42 CROND[17982]: (root) CMD (php /var/www/html/myproject/artisan schedule:run >> /dev/null 2>&1)
Apr 11 19:19:01 ip-10-0-0-42 CROND[17992]: (root) CMD (php /var/www/html/myproject/artisan schedule:run >> /dev/null 2>&1)
Apr 11 19:19:01 ip-10-0-0-42 CROND[17993]: (ec2-user) CMD (php /var/www/html/myproject/artisan schedule:run >> /dev/null 2>&1)
Apr 11 19:19:01 ip-10-0-0-42 CROND[17994]: (apache) CMD (php /var/www/html/myproject/artisan schedule:run >> /dev/null 2>&1)
nothing appearing in either of these:
sudo tail -f /var/www/html/myproject/storage/log/laravel.log
or
sudo tail -f /var/www/html/myproject/storage/log/laravel-2017-04-11.log
Additional Info
Kernel permissions:
drwxr-sr-x 2 apache apache 4096 Feb 24 00:24 Commands
-rw-r--r-- 1 apache apache 1111 Feb 24 00:24 Kernel.php
Resources checked:
- https://askubuntu.com/q/23009
- https://github.com/laravel/framework/issues/13462
- https://mcmap.net/q/843480/-laravel-5-schedule-not-working
- https://laracasts.com/discuss/channels/servers/how-to-perform-php-artisan-schedulerun-on-an-ubuntu-server-with-laravel-53-for-cron-jobs?page=1
Other info:
- running Laravel 5.4.16 as determined by
php artisan --version
- running PHP 7.1.3 as determined by
php -v