Laravel scheduler is not running automatically
Stefan Bogdanescu
Founder & Senior Architect · 2026-06-29
Why Your Laravel Scheduler Isn't Running Automatically: A Deep Dive into Artisan Scheduling
As a senior developer working with the Laravel ecosystem, you often run into situations where code works perfectly when executed manually via the command line, but fails to execute automatically when scheduled. This is a very common hurdle when setting up background tasks. You have correctly defined your schedule within Kernel.php, but the system isn't picking it up.
This post will walk you through the exact mechanism of how Laravel scheduling works and detail the critical step you are likely missing to make your commands run automatically every minute, hour, or day.
Understanding the Laravel Scheduler Mechanism
You have set up your scheduler correctly in app/Console/Kernel.php:
protected $commands = [
\App\Console\Commands\UserRanking::class,
];
protected function schedule(Schedule $schedule)
{
$schedule->command('userRanking')
->everyMinute();
}
This code block merely defines the rules for execution. It tells Laravel: "When the scheduler runs, please note that the userRanking command should be executed every minute."
However, defining a schedule is only half the battle. The actual process of checking this schedule and dispatching the commands to the system is handled by a separate Artisan command: php artisan schedule:run.
When you run php artisan userRanking manually, you are bypassing the scheduler entirely and executing the task directly. To make the scheduler work automatically, you need an external mechanism—the operating system's cron job—to periodically execute this runner command.
The Missing Link: Cron Jobs and System Execution
Laravel itself is just a framework; it relies on the underlying operating system (Linux/macOS) to manage recurring tasks. For Laravel scheduled jobs to run automatically, you must configure a cron job on your server.
A cron job is a time-based job scheduler in Unix-like operating systems. It allows you to execute commands periodically at fixed times, dates, or intervals.
Step 1: Ensure the Application is Executable via CLI
Before setting up the cron, ensure that the PHP environment and the Laravel application are accessible from the command line where the cron job will run. This usually involves using the full path to the PHP executable and ensuring you are running the command from the correct project root directory.
Step 2: Setting Up the Cron Entry
You need to edit your server’s crontab file (usually done via crontab -e). You will add a line that tells the system to execute the Laravel scheduler command every minute.
Here is an example of what your crontab entry might look like. This assumes you want the scheduler to run every minute:
* * * * * cd /path/to/your/laravel/project && php artisan schedule:run >> /dev/null 2>&1
Explanation of the Cron Entry:
* * * * *: This is the schedule frequency (every minute).cd /path/to/your/laravel/project: This changes the working directory to your Laravel project root. This is crucial so that Artisan can find the necessary files and configuration.&& php artisan schedule:run: This executes the command that tells Laravel to check its schedule and run any pending tasks.>> /dev/null 2>&1: This redirects all output (both standard output and errors) to null, keeping your server logs clean unless an actual error occurs.
Best Practices for Scheduled Tasks
When dealing with scheduled tasks, especially those running frequently, keep the following best practices in mind:
- Error Handling is Critical: If a scheduled job fails, you need to know about it. Do not rely solely on redirecting output to
/dev/null. Configure your cron job to email errors or log them to a dedicated file for easy debugging. - Use Queues for Heavy Lifting: For long-running or computationally intensive tasks (like complex user ranking algorithms), avoid running them directly inside the
schedulemethod. Instead, dispatch the command to a queue. This keeps your web requests fast and allows you to manage task retries using Laravel Queues—a powerful feature provided by frameworks like those discussed on laravelcompany.com. - Separate Concerns: Keep scheduling logic separate from heavy business logic. The
schedulemethod should only be responsible for dispatching the command; the command itself should handle the actual work.
Conclusion
The key takeaway is that defining a schedule in Laravel is just the first step. To activate that schedule, you must properly configure the operating system scheduler (cron) to periodically execute the dispatcher command: php artisan schedule:run. By correctly setting up this external execution layer, you unlock the full power of scheduled tasks in your Laravel application, ensuring your rankings and recurring processes operate seamlessly in the background.