Mr. Kenneth
Mr. Kenneth

Reputation: 926

Cronjob not firing Laravel Function Schedule

Based on what I read on the documentation and other SO Questions, I need to add * * * * * cd /path-to-your-project && php artisan schedule:run >> /dev/null 2>&1 on crontab -e and check with crontab -l just to confirm that the every minute cron was added. The cron item added runs the protected function schedule inside app\Console\Kernel every minute. Everything works on local and development. However on the production, the cron is not running the schedule at all.

What I tried:

Add a dummy cronjob * * * * * php echo "something" >> /path-to-your-project/storage/logs/test.txt

Add a Log::info("TEST"); inside function schedule() both develop and production.

Note: I tried to manually run php artisan command:command and the command does run (with and without sudo).

Note2: I checked /var/logs/cron and I can see both the php artisan and php echo being logged.

Note3: manually running php artisan schedule:run, I can see in the terminal the text No scheduled commands are ready to run. And the Log inside the schedule was also written.

Is there any part that I missed? Is my setup wrong?

Upvotes: 0

Views: 727

Answers (2)

Mr. Kenneth
Mr. Kenneth

Reputation: 926

I was able to run my php/artisan script using cron. The command used was:

* * * * * /bin/php7 /path-to-project/artisan schedule:run >> /dev/null 2>&1

Where /bin/php7 is the command to execute php scripts. Might be because of how the server was setup.

Upvotes: 0

Bhargav Chudasama
Bhargav Chudasama

Reputation: 7171

check your php path and set as per your path /usr/bin/php /var/www/html/artisan

use

* * * * * /usr/bin/php /var/www/html/artisan schedule:run >> /dev/null 2>&1

instead of

* * * * * cd /path-to-your-project && php artisan schedule:run >> /dev/null 2>&1

Upvotes: 2

Related Questions