Laravel + Crontab not working

14,849

Solution 1

This part just puts the output into oblivion so you'll never see it:

>> /dev/null 2>&1

Why not try:

* * * * * php /var/www/myproject/artisan schedule:run >> /my_path/example.txt 

And check to see if the cron is run in /my_path/example.txt

The default inspire command essentially just echo's a quote so the only way to see it in a cron is to output it to a file on the server.

You can do this using something similar to this:

$schedule->command('inspire')->everyMinute()->appendOutputTo($filePath);

Further details: https://laravel.com/docs/5.4/scheduling#task-output

Solution 2

Am also using laravel 4.2, Here is my Cron command which currently working good.

0   0   *   *   *   /usr/local/bin/php /*****/******/public_html/artisan command:firemyevent

Hope It will help you.

Solution 3

you should try something

like * * * * * cd /Path/TO/YOUR_PROJECT/ && php artisan schedule:run >> /dev/null 2>&1

Solution 4

in my case, I had to explicity a php version compatible with laravel, in my cron job:

cd /path/to/my/project && /usr/local/bin/ea-php71 artisan schedule:run > /dev/null 2>&1
Share:
14,849
prgrm
Author by

prgrm

I´m a web programmer

Updated on June 21, 2022

Comments

  • prgrm
    prgrm almost 2 years

    I am trying to set up scheduler in Laravel.

    Here is my crontab which I debugged and works fine - atleast with my cron job

    * * * * * /bin/echo "foobar" >> /my_path/example.txt 
    

    I don't know if this one works:

    * * * * * php /var/www/myproject/artisan schedule:run 1>> /dev/null 2>&1
    

    Here is my schedule function in Kernel:

       protected function schedule(Schedule $schedule)
        {
             $schedule->command('inspire')
                     ->everyMinute();
        }
    

    When I am in my project and try php artisan inspire it actually works, so I expected it to fire every minute, but it won't do anything. Nothing happens.

    Any ideas?

  • prgrm
    prgrm about 7 years
    tried this one. example.txt contains: Running scheduled command: '/usr/bin/php' 'artisan' inspire > '/dev/null' 2>&1
  • Rhu
    Rhu about 7 years
    This show's it is working correctly, next you can try outputing it to a specific file: laravel.com/docs/5.4/scheduling#task-output using $schedule->command('inspire')->everyMinute()->appendOutputTo‌​($filePath); or something similar.
  • btx
    btx almost 4 years
    /usr/local/bin/php solved the issue to run inside docker container!