Run Laravel Queue Workers with Supervisor
- Supervisor can keep a Laravel queue worker running in the background and automatically restart it if the process stops.
Install Supervisor
- On Ubuntu:
sudo apt update
sudo apt install supervisor
- Check that Supervisor is running:
sudo systemctl status supervisor
Create the Laravel Worker Configuration
- Create a new Supervisor configuration file:
sudo nano /etc/supervisor/conf.d/laravel-worker.conf
- Add:
[program:laravel-worker]
process_name=%(program_name)s_%(process_num)02d
command=php /var/www/your-project/artisan queue:work --sleep=3 --tries=3 --timeout=90
autostart=true
autorestart=true
stopasgroup=true
killasgroup=true
user=www-data
numprocs=1
redirect_stderr=true
stdout_logfile=/var/www/your-project/storage/logs/worker.log
stopwaitsecs=3600
- Replace:
/var/www/your-project
- with the actual Laravel project path.
- The
usershould also match the user that should run the Laravel application. On a typical Ubuntu web server this is often:
www-data
Load the Configuration
- After creating or changing the Supervisor configuration:
sudo supervisorctl reread
sudo supervisorctl update
- Start the worker:
sudo supervisorctl start laravel-worker
- Check its status:
sudo supervisorctl status
- You should see something similar to:
laravel-worker RUNNING
Restart the Worker
- If Laravel application code used by queued jobs has changed, restart the queue workers so they load the new code:
php artisan queue:restart
- Laravel allows the currently running job to finish and then restarts the worker safely.
- If the Supervisor configuration itself was changed, run:
sudo supervisorctl reread
sudo supervisorctl update
sudo supervisorctl restart laravel-worker
Useful Supervisor Commands
sudo supervisorctl status
sudo supervisorctl start laravel-worker
sudo supervisorctl stop laravel-worker
sudo supervisorctl restart laravel-worker
php artisan queue:restartis normally used after deploying Laravel code changes.
supervisorctl reread and supervisorctl update are required when the Supervisor configuration file itself has been changed.