Laravel + Crontab Not Working

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?

2

4 Answers

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:

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.

1

you should try something

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

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Maya Lin-Takahashi

Maya Lin-Takahashi

Consumer Tech & Gadget Reviewer

Maya is a hardware enthusiast who tests and reviews smart home devices, smartphones, wearables, and audio gear. She focuses on practical consumer value and build quality.

Share this article
Twitter Facebook Pinterest