Roman
1
I have my laravel app installed on subdomain of my website and I’ve set cronjob but it does not fire.
I’ve tested my command by terminal and its firing just fine so the issue is all about cronjob and not my command/console I guess.
Code
Does not work
1- /home/example.com/public_html/process.example.com && php artisan schedule:run >> /dev/null 2>&1
2- php /home/example.com/public_html/process.example.com && php artisan schedule:run >> /dev/null 2>&1
kernel.php
protected $commands = [
Commands\RenewInvoices::class,
];
protected function schedule(Schedule $schedule)
{
$schedule->command('renew:invoices')
->everyMinute();
}
Any idea?
Logan
2
Correct cronjob command
You need to run the artisan command with the full path to the PHP executable and to the artisan file, like this:
* * * * * /usr/bin/php /home/example.com/public_html/process.example.com/artisan schedule:run >> /dev/null 2>&1
Explanation
/usr/bin/php
— full path to PHP (check yours by running which php
in terminal)
/home/example.com/public_html/process.example.com/artisan
— full path to the artisan
file in your Laravel app
schedule:run
— the artisan command to trigger scheduled tasks
>> /dev/null 2>&1
— silences all output (optional)
How to find PHP path
Run this in terminal:
which php
Use the output path in place of /usr/bin/php
.
Summary
Set your cronjob like this (replace PHP path if needed):
* * * * * /usr/bin/php /home/example.com/public_html/process.example.com/artisan schedule:run >> /dev/null 2>&1
This will run Laravel’s scheduler every minute and fire your commands.