2

When I run 'php artisan schedule:run' in terminal, it's doing what is exptected, but when I configure my crontab to execute it automatically it has no effect. My code in Kernel.php is:

$schedule->call(function () {
            $example=Example::orderBy('updated_at', 'asc')->limit(1)->first();
            $example->touch();
        })->everyMinute();

and in crontab -e I put

* * * * * php /path/to/laravel/project schedule:run 1>> /dev/null 2>&1

I tried executing other commands in the crontab file and the other commands were working. So I suppose that could be something with php but I don't have any output to know whats the problem.

Any idea on how to figure out the problem?

1
  • To make it work: * * * * * php /path/to/laravel/project/artisan schedule:run 1>> /dev/null 2>&1 Commented Oct 11, 2015 at 21:28

2 Answers 2

7

I think you path is not complete. You must include Artisan in your path.

* * * * * php /path/to/artisan schedule:run >> /dev/null 2>&1

So for example:

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

See Laravel documentation for more information: Task Schedule

Edit

If you would like to see the output of your Cronjob then you must remove the following:

>> /dev/null 2>&1
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks you were right, I just added artisan and now is working
3

Sometimes the issue is that Cron does not know where PHP is. In such cases, you have to define the path to your local php installation. In my machine,

crontab -e

has the entry

* * * * * /usr/local/bin/php /home/younus/TruckJee/Code/Panel/artisan schedule:run

It worked perfectly as planned. Also, to check if your crobjobs are running, use

cat /var/log/syslog

It should show if your cronjob is actually running. (ie)

May 23 16:21:01 farveaz cron[1105]: (root) RELOAD (crontabs/root)
May 23 16:21:01 farveaz CRON[6812]: (younus) CMD (/usr/local/bin/php /home/younus/TruckJee/Code/Panel/artisan schedule:run)
May 23 16:21:01 farveaz CRON[6811]: (CRON) info (No MTA installed, discarding output)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.