Framework: cron job on laravel homestead

Created on 5 Apr 2015  路  13Comments  路  Source: laravel/framework

It appears that cron jobs aren't automatically configured on homestead.

I created an artisan command that is meant to run every 5 minutes but it doesn't do anything.
When I call the command in the terminal, it works.

Most helpful comment

Just for others coming from Google:
I had to add schedule: true within sites of Homestead.yaml (see https://laravel.com/docs/5.7/homestead#configuring-cron-schedules)
Then, after vagrant halt and vagrant up --provision it went into effect.

All 13 comments

I had to manually edit crontab:

1) crontab -e
2)Then add * * * * * php /path/to/artisan schedule:run

This made it work.

Why is it not automatically configured???

Does homestead documentation said anything about automatically configuring cron jobs?

No - but it's implied because the standard laravel setup has everything set up to run a cron job:
a) The Kernal file has the inspire artisan command set up to run every hour.

Homestead should honour what laravel has automatically set up. I don't even see a downside for Homestead not automatically having the cron job set up. Laravel 'boasts' how cron jobs can be all configured internally from within the framework: http://laravel.com/docs/master/artisan#scheduling-artisan-commands

Plus it is super easy for homestead to have it automatically configured.

Besides the possibly of Taylor making a mistake in his reasoning OR not thinking about the issue at all, I can only think of one rational reason why Taylor has not done this.

He wants Homestead to mirror Forge. In Forge, you have to manually configure the cron job.
In Forge, they don't necessarily encourage you to run "schedule:run" and let the framework take care of all the cron jobs internally. The documentation and Laracast videos highlight that you can bypass "schedule:run" and manually decide which artisan command jobs you want done from outside the framework.

He wants Homestead to mirror Forge. In Forge, you have to manually configure the cron job.

In Forge, you still have to manually configure it (add it), since Forge and Homestead is not ONLY for Laravel 5, Laravel 4 does not have schedule:run by default and for sure non Laravel app doesn't have artisan command to begin with.

Plus it is super easy for homestead to have it automatically configured.

Both https://github.com/laravel/homestead and https://github.com/laravel/settler are open sourced. It would be super easy to submit Pull Request to add this feature.

I'm not talking about Forge automatically having the cron job set up, for the reasons you state. I'm only talking about Homestead having it set up - at least if it detects L5.

I'll look into doing a pull-request once I learn how to understand what is going on in those scripts.

Can I ask - why are you even running cron jobs on homestead? Its designed for development?

If you're doing development then it'd be reasonable to mimic production as much as possible, not an unreasonable want imo.

edit: in relation to the issue though, I'd +1 a PR for something, although not an automatic setup of the cron on Homestead install.

But why run "crons"? You just run the commands individually to test them - no need to _schedule_ them to run at certain times.

It doesnt make sense in a development environment and it should not be the default to have them enabled.

In fact - it can be dangerous/problematic to run them in a development environment, because you'll have code running against your app while you are making changes. There will be many times the cron will fail with PHP errors since your code is not able to be run while you are in the middle of making changes.

I personally would do that, yes, but I think that giving people options is also good, e.g. multiple ways to set up your routes, validate requests, setup your middleware, etc.

In any case, not worth arguing about, issue should probably be closed and if someone wants to PR it over at laravel/homestead or laravel/settler (not sure which this would go under honestly, haven't looked into either of them much, hopefully someone can help there) then they can

This belongs on the forums.

As a brand new homestead user, I would love to see this feature included. It would be awesome if I can define in Homestead.yaml.

FYI this issue comes on top of google search for this feature.

Adding to Homestead.yaml might be the best option. I feel this feature should be off by default but can be easily enabled via an additional option in Homestead.yaml.

However.. having Homestead managing crontab may lead to other issues, since developers might use crontab for other requirements as well, it should make sure that the changes won't override those customized fields.

Just for others coming from Google:
I had to add schedule: true within sites of Homestead.yaml (see https://laravel.com/docs/5.7/homestead#configuring-cron-schedules)
Then, after vagrant halt and vagrant up --provision it went into effect.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

shopblocks picture shopblocks  路  3Comments

jackmu95 picture jackmu95  路  3Comments

kerbylav picture kerbylav  路  3Comments

JamborJan picture JamborJan  路  3Comments

iivanov2 picture iivanov2  路  3Comments