🛠 Step 1: Install Supervisor
For Ubuntu/Debian
sudo apt update && sudo apt install supervisor -y
For CentOS/RHEL
sudo yum install supervisor -y
🚀 Step 2: Enable and Start Supervisor
Enable Supervisor to start on boot and start the service:
sudo systemctl enable --now supervisor
Check its status:
sudo systemctl status supervisor
If Supervisor is not running, start it manually:
sudo systemctl start supervisor
📁 Step 3: Create a Supervisor Configuration for Laravel Queue
-
Open a new Supervisor config file:
sudo nano /etc/supervisor/conf.d/laravel-worker.conf -
Add the following content (modify the paths according to your Laravel project directory):
[program:laravel-worker] process_name=%(program_name)s_%(process_num)02d command=php /var/www/html/your-laravel-project/artisan queue:work --tries=3 autostart=true autorestart=true numprocs=1 user=www-data redirect_stderr=true stdout_logfile=/var/www/html/your-laravel-project/storage/logs/worker.logExplanation of the options:
command→ Runsphp artisan queue:workautostart=true→ Automatically starts when Supervisor startsautorestart=true→ Restarts automatically if it crashesnumprocs=1→ Runs 1 worker processuser=www-data→ Runs as the web server user (modify if needed)stdout_logfile→ Logs worker output (useful for debugging)
-
Save the file (
CTRL + X, thenY, thenEnter).
🔄 Step 4: Reload and Start Supervisor
- Tell Supervisor to read the new config:
sudo supervisorctl reread - Update Supervisor with new programs:
sudo supervisorctl update - Start the Laravel queue worker:
sudo supervisorctl start laravel-worker - Check the status of the worker:
sudo supervisorctl status
🛠 Step 5: Ensure Supervisor Runs on System Reboot
Run this to make sure Supervisor restarts when the server reboots:
sudo systemctl enable supervisor
🔍 Step 6: Monitor Supervisor and Laravel Worker
Check if the worker is running:
sudo supervisorctl status
Restart the worker if needed:
sudo supervisorctl restart laravel-worker
Stop the worker:
sudo supervisorctl stop laravel-worker
Check Supervisor logs for errors:
sudo tail -f /var/log/supervisor/supervisord.log
Check Laravel queue logs:
tail -f /var/www/html/your-laravel-project/storage/logs/worker.log
🚀 Step 7: Test the Queue
- Make sure your
.envfile is set to use a queue driver other thansync(e.g.,database,redis, etc.):QUEUE_CONNECTION=database - Run migrations if using a database queue:
php artisan queue:table php artisan migrate - Dispatch a test job:
php artisan queue:work - If your job gets processed, Supervisor is working correctly!
✅ Summary of Commands
| Action | Command |
|---|---|
| Install Supervisor | sudo apt install supervisor -y |
| Start Supervisor | sudo systemctl start supervisor |
| Enable Supervisor on boot | sudo systemctl enable supervisor |
| Create a Laravel queue worker config | sudo nano /etc/supervisor/conf.d/laravel-worker.conf |
| Reload Supervisor config | sudo supervisorctl reread |
| Update Supervisor programs | sudo supervisorctl update |
| Start Laravel queue worker | sudo supervisorctl start laravel-worker |
| Restart Laravel queue worker | sudo supervisorctl restart laravel-worker |
| Check worker status | sudo supervisorctl status |
| Check Supervisor logs | sudo tail -f /var/log/supervisor/supervisord.log |
| Check Laravel queue logs | tail -f /var/www/html/your-laravel-project/storage/logs/worker.log |
🎯 Final Thoughts
- If Supervisor fails to start, check its logs (
/var/log/supervisor/supervisord.log). - If jobs are not processing, check Laravel’s logs (
storage/logs/laravel.log). - If the queue stops working after reboot, ensure Supervisor is enabled (
sudo systemctl enable supervisor).