Norgul
Norgul

Reputation: 4783

Digitalocean cron and Laravel

I have a hard time running cron job on Digitalocean. I noticed there are two different cron files, I get to one by getting to /etc/crontab and other one by entering the command crontab -e.

To make it more confusing, both of those have somewhat different "layout". First one:

* *     * * *   root    php /var/www/Laravel artisan schedule:run >> /home/laravel.log

and second one:

* * * * * php /var/www/Laravel artisan schedule:run >> laravel.log

Here is Laravel scheduler part:

protected $commands = [
    'App\Console\Commands\SyncAPIs',
];

/**
 * Define the application's command schedule.
 *
 * @param  \Illuminate\Console\Scheduling\Schedule  $schedule
 * @return void
 */
protected function schedule(Schedule $schedule)
{
    $schedule->command('media:sync')->everyThirtyMinutes();

    // sync for yesterday to eliminate discrepancies
    $schedule->command('media:sync ' . Carbon::yesterday())->dailyAt(6);
}

The thing is that the laravel.log does get created, but I see nothing in it, and I don't know if my commands actually get ran. Does that mean that cron IS actually running? How can I debug the issue as I don't see in the database that cron filled it. When I go to the folder /var/www/Laravel and execute the commands which are supposed to be called in scheduler, dataabse fills correctly.

Upvotes: 0

Views: 2433

Answers (3)

cd ~
crontab -u root -e
* * * * * php /var/www/laravelprojectname/artisan schedule:run 1>> /dev/null 2>&1
service cron restart
grep -i cron /var/log/syslog|tail -3

I think this should help

Upvotes: 1

Norgul
Norgul

Reputation: 4783

I found an answer being actually:

* * * * * php /var/www/Laravel/artisan schedule:run >> laravel.log

php works globally, but artisan needs to be shown the path which is in my Laravel main folder

Upvotes: 0

MEDALI
MEDALI

Reputation: 55

May be you need to change this line :

* * * * * php /var/www/Laravel artisan schedule:run >> laravel.log

to :

* * * * * /usr/bin/php /var/www/Laravel artisan schedule:run >> laravel.log

Upvotes: 0

Related Questions