Setting Up Laravel Queue Workers on Ubuntu with PHP 8.3: A Step-by-Step Guide

To set up php artisan queue:work --queue on Ubuntu, follow these steps:
Step 1: Ensure Your Environment is Ready
Install PHP and Composer (if not already installed):
sudo apt update sudo apt install php-cli php-mbstring unzip curl curl -sS https://getcomposer.org/installer | php sudo mv composer.phar /usr/local/bin/composerInstall Supervisor (for managing background processes):
sudo apt install supervisor
Step 2: Set Up the Laravel Queue Worker
Navigate to Your Laravel Project Directory:
cd /path/to/your/laravel/projectRun the Queue Worker Command to Test:
php artisan queue:work --queue=high,default,lowReplace
high,default,lowwith your specific queue names.If Successful, Configure Supervisor for Continuous Running.
Step 3: Configure Supervisor
Create a Configuration File for Supervisor:
sudo nano /etc/supervisor/conf.d/laravel-worker.confAdd the Following Configuration:
[program:laravel-worker] process_name=%(program_name)s_%(process_num)02d command=/usr/bin/php8.1 /path/to/your/laravel/project/artisan queue:work --queue=high,default,low --sleep=3 --tries=3 autostart=true autorestart=true user=www-data numprocs=1 redirect_stderr=true stdout_logfile=/path/to/your/laravel/project/storage/logs/worker.logor
[program:laravel-worker]
process_name=%(program_name)s_%(process_num)02d
command=/usr/bin/php8.3 /var/www/html/PrimeAuraHealth-API/artisan queue:work database --queue=emails --sleep=3 --tries=3 --timeout=120
directory=/var/www/html/PrimeAuraHealth-API
autostart=true
autorestart=true
user=www-data
numprocs=1
redirect_stderr=true
stdout_logfile=/var/www/html/PrimeAuraHealth-API/storage/logs/worker.log
stopwaitsecs=360
stopsignal=QUIT
- Save and Exit.
✅ How to Add Another Worker (for another website)
For a second Laravel project, you must create a new Supervisor program with a different name.
Example:
New file
/etc/supervisor/conf.d/laravel-worker-2.conf
(or any name you want)
Content:
[program:laravel-worker-2]
process_name=%(program_name)s_%(process_num)02d
command=/usr/bin/php8.3 /var/www/html/OtherLaravelProject/artisan queue:work database --queue=emails --sleep=3 --tries=3 --timeout=120
directory=/var/www/html/OtherLaravelProject
autostart=true
autorestart=true
user=www-data
numprocs=1
redirect_stderr=true
stdout_logfile=/var/www/html/OtherLaravelProject/storage/logs/worker.log
stopwaitsecs=360
stopsignal=QUIT
Just change:
✔ program: name
✔ project directory path
✔ command path
✔ log file path
🟢 After saving, run these commands:
sudo supervisorctl reread
sudo supervisorctl update
sudo supervisorctl start laravel-worker-2:*
🧠 Important Notes:
1. You cannot reuse the same program name
If you use [program:laravel-worker] again → conflict.
Step 4: Enable and Start Supervisor
Reload Supervisor to Apply Changes:
sudo supervisorctl reread sudo supervisorctl update or sudo supervisorctl reread sudo supervisorctl update sudo supervisorctl restart laravel-worker:Start the Laravel Worker:
sudo supervisorctl start laravel-worker:*
Step 5: Monitor and Debug
Check the Logs:
tail -f /path/to/your/laravel/project/storage/logs/worker.logView Supervisor Status:
sudo supervisorctl status
This setup ensures that your Laravel queues are always processed in the background, even after server restarts.



