📦 What is Supervisor?
Supervisor is a Linux process monitor that keeps your Laravel queue workers running continuously and restarts them automatically if they fail.
⏰ What is Crontab?
Crontab is a Unix utility that runs scripts or commands at scheduled times. In Laravel, this is used for running scheduled tasks defined in your app/Console/Kernel.php
in Laravel 10+ routes/console.php
.
Before you start, make sure you have:
- Laravel project set up and ready to use
- Root or sudo access to the server
- Your project path and domain correctly configured
Step 1: Install Supervisor
Install Supervisor on Ubuntu:
sudo apt-get install supervisor
sudo service supervisor restart
Step 2: Create a Supervisor Configuration File
Open the configuration file for editing:
sudo vim /etc/supervisor/conf.d/laravel-worker.conf
Paste the following configuration:
[program:laravel-worker]
process_name=%(program_name)s_%(process_num)02d
command=php /var/www/html/yourdomain.com/artisan queue:work
autostart=true
autorestart=true
stopasgroup=true
killasgroup=true
user=root
numprocs=8
redirect_stderr=true
stdout_logfile=/var/www/html/yourdomain.com/worker.log
stopwaitsecs=3600
Replace /var/www/html/yourdomain.com/
with the actual path to your Laravel project.
Step 3: Start Supervisor with Your Configuration
Reload Supervisor to recognize the new config and start the worker:
sudo supervisorctl reread
sudo supervisorctl update
sudo supervisorctl start laravel-worker:*
To check the worker status:
sudo supervisorctl status
Step 4: Set Up Laravel Scheduler with Cron
Open the crontab configuration:
crontab -e
Add this line to run Laravel's scheduler every minute:
* * * * * cd /var/www/html/yourdomain.com && php artisan schedule:run >> /dev/null 2>&1
Replace the path with your actual Laravel app directory.
Optional: Uninstall Supervisor
If needed, you can remove Supervisor using:
sudo apt-get remove supervisor
sudo apt-get autoremove
Questions or feedback? Drop a comment!
Top comments (0)