简体   繁体   中英

Laravel cronjob in server won't run

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?

Solved

Apparently I had to get my php from other place /usr/local/lsws/lsphp74/bin/php rather than /usr/bin/php

/usr/local/lsws/lsphp74/bin/php /home/example.com/public_html/process.example.com && /usr/local/lsws/lsphp74/bin/php /home/example.com/public_html/process.example.com/artisan schedule:run >> /dev/null 2>&1

To simplify command above and make it easy to read here is it's structure:

PHP LARAVEL_APP && PHP ARTISAN COMMAND >> /dev/null 2>&1

Cronjobs ignore PATH when it is run, so it may not work if the PATH information is not fully available to it.

Please try amending the cronjob so that the full path is used

For example, change "php" to "/usr/bin/php" (pls use your actual path of php in your server)

 /home/example.com/public_html/process.example.com && /usr/bin/php artisan schedule:run >> /dev/null 2>&1

/usr/bin/php /home/example.com/public_html/process.example.com && /usr/bin/php artisan schedule:run >> /dev/null 2>&1

Please also include the full path of artisan. Thanks

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM