Laravel schedule:run is not working when added into the cron job

Viewed 4651

I have made a command and scheduled it for every 30 minutes. When I run php artisan schedule:run it works perfectly fine and returns with the expected results, but when I configured it on my live server my cron job do run but instead of retuning the success message it returns with list of all available command in my laravel project. Here is what I am doing.

Command Kernel:

$schedule->command('update:callLogs')
            ->everyMinute();

Cron Entry:

/usr/bin/php /home/ddsas9rm2f1g/public_html/clowdlink.com/crm/artisan schedule:run

And this is the response I am getting

Laravel Framework 5.8.38

Usage:
command [options] [arguments]

Options:
 -h, --help            Display this help message
 -q, --quiet           Do not output any message
 -V, --version         Display this application version
  --ansi            Force ANSI output
  --no-ansi         Disable ANSI output
 -n, --no-interaction  Do not ask any interactive question
  --env[=ENV]       The environment the command should run under
 -v|vv|vvv, --verbose  Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug

Available commands:
 (List of all availabe commands)

Any help will be much appreciated.

EDIT Now my command looks like this

* * * * * cd /home/ddsas9rm2f1g/public_html/clowdlink.com/crm && php artisan update:callLogs

but getting the same response whereas when I copy the same command and using putty ran the same command and it works perfectly fine. Now it's been a week now and I'm still stuck at this cron thing.

5 Answers

I fixed this by specifying the path to PHP instead of using just php.

From this: cd /home/foobar && php artisan schedule:run

To this: cd /home/foobar && /usr/local/bin/php artisan schedule:run

This stopped me from getting a list of available artisan commands and gave me the right output.

I can see it looks like you've already tried that, but I think others will run into this too. I'd imagine your issue is something to do with the PHP version you're using not being able to properly run PHP scripts. Maybe an opcache thing with CLI?

I faced big challenge as well when I was deploying one my applications, and finally managed to tackle it with:

cd /path-to-project && /opt/cpanel/ea-php71/root/opt/cpanel/ea-php74/root/usr/bin/php-cgi artisan schedule:run

I use Laravel 5.7 for my application

You could try the following code:

* * * * * php /home/ddsas9rm2f1g/public_html/clowdlink.com/crm/artisan schedule:run 1>> /dev/null 2>&1

>> /dev/null 2>&1: we will discard all output of a command.

Can you try the below in cron and share the output of crontab.out

* * * * * cd /home/ddsas9rm2f1g/public_html/clowdlink.com/crm/ && php artisan schedule:run >> crontab.out 2>&1
*/30 * * * * php /home/ddsas9rm2f1g/public_html/clowdlink.com/crm/artisan schedule:run 1>> /dev/null 2>&1

OR

*/30 * * * * /usr/bin/php /home/ddsas9rm2f1g/public_html/clowdlink.com/crm/artisan schedule:run 1>> /dev/null 2>&1

OR

*/30 * * * * cd /home/ddsas9rm2f1g/public_html/clowdlink.com/crm && php artisan schedule:run >> /dev/null 2>&1

Also read full post: https://devnote.in/how-to-set-auto-database-backup-with-cron-scheduler-in-laravel/

Related