
When managing websites or applications, certain tasks need to run regularly—like sending emails, cleaning up databases, or generating reports. Without automation, these tasks would have to be done manually, which can take up valuable time.
That’s where Cron jobs come in.
Cron is a tool in Unix/Linux systems that automates tasks, running them on a set schedule like hourly, daily, or weekly.
Laravel makes this process even easier by offering its own built-in scheduling system for Cron jobs. Instead of writing complex Cron expressions by hand, Laravel allows you to manage scheduled tasks through simple code, making it faster and more efficient.
In this guide, I’ll walk through a practical example of setting up a custom Artisan command and scheduling it to run at specific intervals, ensuring your recurring tasks are handled effortlessly.
How Cronjob Works?
As I mentioned earlier, a Cron job is a way to run commands automatically at set times.
To schedule a task, you use a file called crontab. This file contains a list of commands and when to run them. Each line has two parts: the time settings and the command to execute.
The format looks like this:
* * * * * command_to_run
Here’s what each star means:
- First: minute (0–59)
- Second: hour (0–23)
- Third: day of the month (1–31)
- Fourth: month (1–12)
- Fifth: day of the week (0–6, where Sunday is 0)
If you want to run a command every day at 3:00 AM, you’d write:
0 3 * * * command_to_run
In Laravel, you usually create a custom command and define its schedule inside your project. Then you just need one line in your server’s crontab:
* * * * * php /path-to-your-project/artisan schedule:run >> /dev/null 2>&1
This tells Laravel to check every minute if there’s anything scheduled to run, and it handles everything else from inside the app.
Struggling With Server Setup, Cron Jobs, & Performance Issues?
Cloudways handle server management for you so you can focus on creating great apps and keeping your clients happy.
Laravel Cron Job Scheduling
Laravel makes task scheduling straightforward. Its built-in Command Scheduler lets you define when specific commands should run—right inside your Laravel project.
To use it, you only need to add a single Cron entry to your server. Once that’s in place, you define your task schedule in the schedule method inside app/Console/Kernel.php.
Let’s walk through a quick example. Suppose you want to create a custom Artisan command that sends an email report to all users every hour. Here’s how you’d set that up.
How to Create a Cron Job in Laravel?
I’m going to assume you already have a Laravel application set up. If that’s the case, feel free to skip ahead to the section where we’ll create a custom Artisan command and schedule it.
If not, don’t worry—you can follow along by setting up a fresh Laravel app first.
Installing Laravel Application
For this tutorial, I’ll be using the Cloudways Platform because it offers a 1-click Laravel installation, which makes setup quick and hassle-free.
- To get started, sign up for a free Cloudways account and log in.
- Then, create a new server and choose Laravel as the application type. Fill in your server and app details, hit “Launch Now”—and you’re all set.
Optional: Update to the Latest Laravel Version 12x
- Once your server is ready, go to the Servers tab in the Cloudways dashboard.
- Select the server you just created.
- Now head to Settings & Packages, then Packages.
- You’ll see your currently installed PHP version. Click the modify drop-down to upgrade to the latest version.
- In my case, it is PHP 8.2, so I’ll leave it as is.
- Now that we’ve updated the PHP version, we can now install Laravel 12. To do this, you’ll need to open the SSH terminal and run the Composer command to start the Laravel 12 installation process on the server.
- Head to Master Credentials. This is where you’ll find SFTP and SSH access details for all applications.
- Click on the Launch SSH Terminal button.
- Now log in using your Username and Password. You can find it in the Master Credentials tab.
- Once logged in, navigate to your application folder: cd /home/master/applications/your-app-id/private_html. You can get your app ID from your Cloudways dashboard in the Access Details tab.
/home/master/applications/your-app-id/private_html
because when you launch a server on Cloudways with a Laravel application, it installs Laravel by default into the public_html
directory. So to install Laravel 12, we have to do that inside private_html
. This way, we avoid interfering with the existing app and can safely install Laravel 12 in parallel. This won’t replace the default Laravel 10 install. But if you later decide to replace the old Laravel 10 app with your new Laravel 12 installation, you can do that by pointing the public_html
folder to the /public
directory of your Laravel 12 app. For now, we’ll keep both versions running side by side: Laravel 10 for the frontend, and Laravel 12 for backend scripts or testing.- Once logged in, inside private_html, run: composer create-project laravel/laravel:^12 my-new-laravel-app. You can replace my-new-laravel-app with whatever name you want for the new app folder.
- To verify your Laravel 12 installation, head to the new Laravel directory you created: cd my-new-laravel-app.
- Run the following command in your Laravel project directory to ensure you are running Laravel 12: php artisan –version
That is it. The output shows that the Laravel 12 application has been set up and the required packages have been installed.
Set Up Laravel Cron Job
To set up a Laravel cron job, the first step is to create a custom Artisan command. Artisan is Laravel’s built-in command-line tool that helps automate common tasks.
For this tutorial, we’ll create a command called HourlyUpdate that you can later schedule to run automatically.
1. Create a Custom Artisan Command
Start by navigating into the Laravel 12 project directory. If you followed the steps earlier, my Laravel 12 app is located in:
cd /home/master/applications/ufgwymvjfb/private_html/my-new-laravel-app
Once inside your Laravel project folder, run this command:
php artisan make:command HourlyUpdate
This will generate a new file at app/Console/Commands/HourlyUpdate.php. This is where you’ll define the logic for whatever task you want to automate.
You’ve just created your custom Artisan command HourlyUpdate.php.
2. Edit the Command File
Now that your HourlyUpdate command has been created, it’s time to define what it actually does.
Open the command file in a terminal editor (like nano). Run this command in the same SSH window where we created the Artisan command earlier:
nano app/Console/Commands/HourlyUpdate.php
Now, you should see the nano editor. Inside this file, you’ll see a couple of placeholder lines that need updating.
Replace everything inside with this example command structure (you can tweak the logic inside handle() based on what you want the command to do):
<?php namespace App\Console\Commands; use Illuminate\Console\Command; class HourlyUpdate extends Command { protected $signature = 'hourly:update'; protected $description = 'Run tasks that need to execute every hour'; public function __construct() { parent::__construct(); } public function handle() { // Your logic here \Log::info("HourlyUpdate command ran at " . now()); $this->info('Hourly update command executed.'); } }
When you’re done adding the code:
- Press Ctrl + O (then press Enter to confirm saving)
- Then Ctrl + X to exit
3. Register the Command
In order for Laravel to recognize and use your new command, you need to register it in the Kernel.php file.
Open the app/Console/Kernel.php file:
nano app/Console/Kernel.php
In my case, the app/Console/Kernel.php file is empty, which isn’t typical for a Laravel project.
Normally, this file contains the necessary structure to define and schedule commands, including the schedule method and the $commands array.
No worries, let’s recreate the essential parts of this file.
Here is what the basic Kernel.php file should look like:
<?php namespace App\Console; use Illuminate\Console\Scheduling\Schedule; use Illuminate\Foundation\Console\Kernel as ConsoleKernel; class Kernel extends ConsoleKernel { /** * The Artisan commands provided by your application. * * @var array */ protected $commands = [ // Register the new command here Commands\HourlyUpdate::class, ]; /** * Define the application's command schedule. * * @param \Illuminate\Console\Scheduling\Schedule $schedule * @return void */ protected function schedule(Schedule $schedule) { // Schedule the hourly command to run every hour $schedule->command('hourly:update')->hourly(); } /** * Register the commands for the application. * * @return void */ protected function commands() { $this->load(__DIR__.'/Commands'); require base_path('routes/console.php'); } }
- Paste the code above in the file, and as earlier, press Ctrl + O to save the file.
- Then press Enter to confirm the file name.
- Exit the editor by pressing Ctrl + X.
So what’s happening here?
Earlier, we created a custom command called HourlyUpdate. We could’ve named it anything, for example, SendNewsletter, CleanTempFiles, or UpdateStats — whatever makes sense for your task.
Now, in the App\Console\Kernel class, we’re telling Laravel two things:
1. Register the command
protected $commands = [ Commands\HourlyUpdate::class, ];
This lets Laravel know about our custom command so it can run it when scheduled.
2. Schedule when it should run
$schedule->command('hourly:update')->hourly();
This schedules the command to run once every hour using Laravel’s ->hourly() method.
While ->hourly() is perfect for this example, Laravel gives you a variety of scheduling methods to match different timing needs. Here’s a quick reference:
Method | Description |
->cron(‘* * * * *’) | Run the task on a custom Cron schedule |
->everyMinute() | Run the task every minute |
->everyFiveMinutes() | Run the task every five minutes |
->everyTenMinutes() | Run the task every ten minutes |
->everyThirtyMinutes() | Run the task every thirty minutes |
->hourly() | Run the task every hour |
->hourlyAt(17) | Run the task every hour at 17 mins past |
->daily() | Run the task every day at midnight |
->dailyAt(’13:00′) | Run the task every day at 1:00 PM |
->twiceDaily(1, 13) | Run the task daily at 1:00 AM and 1:00 PM |
->weekly() | Run the task every week |
->monthly() | Run the task every month |
->monthlyOn(4, ’15:00′) | Run the task on the 4th of every month at 3 PM |
->quarterly() | Run the task every quarter |
->yearly() | Run the task every year |
->timezone(‘America/New_York’) | Set the timezone for the schedule |
After this, test the custom command using:
php artisan hourly:update
Success:
Now that it’s successfully running, the next step is to make sure it’s scheduled to run automatically every hour via Laravel’s task scheduler.
4. Set up the Laravel Scheduler in Cron
It’s now time to add a cron job to your server to run Laravel’s scheduler every minute. This will allow Laravel to check if any scheduled tasks (like your hourly command) need to be executed.
Edit the Crontab file:
Open the crontab editor by running:
crontab -e
Add the Scheduler Command:
At the end of the crontab file, add the following line:
* * * * * php /home/master/applications/ufgwymvjfb/private_html/my-new-laravel-app/artisan schedule:run >> /dev/null 2>&1
This will tell cron to run Laravel’s scheduler every minute. Laravel will then check if it’s time to execute any scheduled commands.
Save and Exit:
After adding this line, save and exit the crontab editor:
Since we’re using nano, press Ctrl + O to save, then Ctrl + X to exit.
5. Confirm Your Cron Job Is Working
Now, your HourlyUpdate command should automatically run every hour, as it’s scheduled through the Laravel scheduler.
To confirm that the cron job is working, you can view your active cron jobs by running the following command:
crontab -l
This will list all the cron jobs for the current user. You should see the entry you added: * * * * * php /home/master/applications/ufgwymvjfb/private_html/my-new-laravel-app/artisan schedule:run >> /dev/null 2>&1
In our case, we can see that in the screenshot above, so it’s a success.
To be extra sure, you can run your cron job manually with the following command (this will bypass the cron job scheduler and execute the command directly):
If it executes properly and outputs “Hourly update command executed.“, you know the command works and is ready for scheduling.
And as you can see, it works:
How Cloudways Makes Setting Up Laravel Cron Jobs Easier?
Earlier, we walked through how to set up a Laravel cron job manually using SSH — creating the HourlyUpdate command, registering it, scheduling it in Laravel, and then configuring the system-wide crontab.
That approach works, and it’s solid if you’re comfortable using the command line. But if your application is hosted on Cloudways, there’s actually a much simpler way to handle it — no need to touch the terminal or edit server files manually.
Here’s how you can do the same thing — running php artisan schedule:run every minute — through the Cloudways platform:
Setting Up Laravel Scheduler on Cloudways
- Go to your Cloudways account and open the application you want to work on.
- From the left-hand menu, click on Cron Job Management.
- Switch to the Advanced tab — this gives you full control over the command format.
- Enter the command below, replacing your_project_folder_name with your actual app folder: * * * * * php /home/master/applications/your_project_folder_name/public_html/artisan schedule:run >> /dev/null 2>&1
- I’ll add this command in my case: * * * * * php /home/master/applications/ufgwymvjfb/private_html/my-new-laravel-app/artisan schedule:run >> /dev/null 2>&1
- This tells the server to check every minute if Laravel has anything scheduled to run — including the hourly update command we set up earlier.
- Hit “Save Changes”, and the scheduler will begin checking for tasks automatically.
Compared to setting things up manually, Cloudways takes care of most of the background setup for you. You still write and schedule your Laravel commands the same way, but running them regularly is just a matter of filling out a field and clicking save.
Effortless Cron Job Scheduling with Cloudways Laravel Hosting
Automate your Laravel tasks in just a few clicks—no server headaches, no complex setups. Cloudways makes running scheduled jobs faster, easier, and worry-free.
Conclusion
Whether you’re comfortable working from the command line or prefer the simplicity of a visual dashboard like the one Cloudways offers, setting up Laravel cron jobs doesn’t need to be complicated.
In this guide, I walked you through the manual route—creating a custom Artisan command, registering it in the Kernel, and setting up a system-level cron job to trigger Laravel’s scheduler every minute.
Then, I showed you how the same task can be handled more easily on Cloudways, using the Cron Job Manager to achieve the same result with far less effort.
Both methods work, but if you’d rather avoid potential slip-ups, the Cloudways approach is definitely the safer bet.
Q) How do I schedule a cron job in Laravel?
To schedule a cron job in Laravel, first open your terminal and navigate to your project root. Edit the crontab file using crontab -e, then add the following line:
Let Cloudways handle the heavy lifting with automated server management, optimized Laravel hosting, and simple cron job scheduling.
* * * * * php /path/to/artisan schedule:run >> /dev/null 2>&1
Next, define your scheduled tasks in app/Console/Kernel.php under the schedule method:
protected function schedule(Schedule $schedule) { $schedule->command('my:command')->everyMinute(); }
Save the changes to the crontab, and your cron job will now run automatically at the defined interval.
Q) What is the purpose of cron jobs in Laravel?
Cron jobs automate recurring tasks like database cleanup, sending notifications, or running scheduled commands at specified intervals without requiring manual intervention.
Q) Can I schedule multiple cron jobs in Laravel?
Yes, you can define multiple scheduled tasks in app/Console/Kernel.php, each with different execution frequencies using Laravel’s scheduler. Each task can be scheduled independently.
Q) What is the difference between a queue and a cron job in Laravel?
Cron jobs are used to execute tasks at scheduled times, such as nightly reports or data cleanup. Queues, on the other hand, handle long-running tasks asynchronously, allowing your application to process jobs in the background without slowing down user requests.
Q) How do I run the Laravel scheduler automatically?
To run the Laravel scheduler automatically, set up a cron job with crontab -e and add:
* * * * * php /path/to/artisan schedule:run >> /dev/null 2>&1
This cron job runs Laravel’s scheduler every minute, executing any scheduled tasks that have been defined in app/Console/Kernel.php.
Q) How do I schedule a cron job every 5 minutes in Laravel?
To schedule a cron job every 5 minutes, edit your crontab with crontab -e and add the following:
*/5 * * * * php /path/to/artisan schedule:run >> /dev/null 2>&1
This ensures your cron job runs every 5 minutes.
Q) How do I check if a Laravel cron job is running?
You can check if the cron service is running by using the following command:
ps aux | grep cron
To manually trigger Laravel’s scheduler and confirm your cron job is executing properly, run the following command in your project root:
php artisan schedule:run
This will immediately execute any tasks scheduled in app/Console/Kernel.php.
Abdul Rehman
Abdul is a tech-savvy, coffee-fueled, and creatively driven marketer who loves keeping up with the latest software updates and tech gadgets. He's also a skilled technical writer who can explain complex concepts simply for a broad audience. Abdul enjoys sharing his knowledge of the Cloud industry through user manuals, documentation, and blog posts.