Add Laravel Scheduler Command to Crontab on Ubuntu


- How to Add the Laravel Scheduler Command to Crontab (on Ubuntu)
- Prerequisites & assumptions
- Step 1: Update & (if needed) install cron
- Step 2: Edit the crontab
- Common pitfalls & tips
- Conclusion
How to Add the Laravel Scheduler Command to Crontab (on Ubuntu)
When building Laravel applications, many background tasks (e.g. cleanup jobs, sending queued emails, recurring reports) are best managed via Laravel’s built‑in scheduler. But to make the scheduler run automatically, you need to hook it into the system cron on your server. In this post, I’ll walk through how to do that on Ubuntu.
Prerequisites & assumptions
Before proceeding, this guide assumes:
- You already have a working Laravel project on Ubuntu (e.g. in
/var/www/…
or some directory). - You have shell / SSH access with sudo (or at least enough rights to edit crontab for a user).
-
cron
service is installed or can be installed. - PHP CLI is accessible from the command line (e.g.
php
works).
Step 1: Update & (if needed) install cron
It’s good practice to ensure your system is up to date, and to confirm cron is installed and running.
sudo apt-get updatesudo apt-get upgrade
Then install cron if it’s not already:
sudo apt-get install cron
After installation, check the status:
systemctl status cron
You should see something like “active (running)”. If it's not running, you may start it:
sudo systemctl enable cronsudo systemctl start cron
Step 2: Edit the crontab
To schedule Laravel’s scheduler, you’ll add a cron entry that runs every minute. Usually you won’t need to touch the system /etc/crontab
(unless you're root or managing many users). Instead, edit the crontab for the relevant user (often the same user under which your web server or application runs).
Run:
crontab -e
If it’s your first time doing this, it may prompt you to choose an editor (like nano, vim, etc.).
In the crontab file, add this line:
* * * * * cd /path-to-your-project && php artisan schedule:run >> /dev/null 2>&1
Make sure to replace /path-to-your-project
with your actual path (for example, /var/www/html/your-laravel-app
).
After editing, save and exit. Cron will pick up the change automatically.
Common pitfalls & tips
Issue | Description / Fix |
---|---|
Wrong path | If cd points to a non-existent directory, cron will fail silently. Double-check absolute path. |
Wrong PHP binary | Sometimes the CLI PHP version is different or not in $PATH . Use full path (e.g. /usr/bin/php ). |
Permissions & ownership | Ensure the user whose crontab you edit has permissions to run the commands and access project files. |
Output flooding / emails | Without redirecting output, cron may send an email on every run. That’s why we use >> /dev/null 2>&1 . |
Multiple crontab entries | If you already have a cron for the same user, ensure this new line doesn’t conflict. |
Conclusion
Integrating Laravel’s scheduler with the system cron is a simple but essential step. Once it’s configured, your application can reliably run scheduled jobs without manual intervention. Just:
- Install/verify cron on Ubuntu
- Add a cron entry (via
crontab -e
) to runphp artisan schedule:run
every minute - Verify everything works
Stay Updated.
I'll you email you as soon as new, fresh content is published.