Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

RenzDeheegher's avatar

Laravel Scheduling and crontabs

Should I use crontabs to automate my scheduled command? Is this the best way to do it / is this a best practice in Laravel to use crontabs with Laravel Scheduling?

Short explanation of what is has to do:

My application is an errormanagementsystem that receives errors from webshops created by this web dev company. Each time the same error occurs and occurrences gets created. An error can be resolved, when it is resolved they want to delete all it's occurrences except the most recent one after 30 days so that the database doesn't become so big. For now I created a command via the Laravel Scheduler that can do this, but I want to automate it using crontabs, or if there is a better option, I'd like to know.

1 like
2 replies
Snapey's avatar
Snapey
Best Answer
Level 122

Yes, you use the crontab to run php artisan schedule:run and then put your command in

V11 onwards: routes/console.php

before V11: Console/Kernel.php

You can read all about the scheduler here. https://laravel.com/docs/12.x/scheduling

Good idea to read through this from end to end.

What this does not tell you is that the crontab is best edited for the user that your web server runs as (often www-data) so that files created by your scheduled jobs are owned by the web server. Do this with;

crontab -e -u www-data
2 likes

Please or to participate in this conversation.