Skip to main content

Command Palette

Search for a command to run...

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

Updated
2 min read
Setting Up Laravel Queue Workers on Ubuntu with PHP 8.3: A Step-by-Step Guide
M

I am Mandeep Singh, a full-stack developer. I created this Blog to bestow my coding experience and love to write on JavaScript, Next.js, Laravel and little bit Unity Game development.

To set up php artisan queue:work --queue on Ubuntu, follow these steps:


Step 1: Ensure Your Environment is Ready

  1. 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/composer
    
  2. Install Supervisor (for managing background processes):

     sudo apt install supervisor
    

Step 2: Set Up the Laravel Queue Worker

  1. Navigate to Your Laravel Project Directory:

     cd /path/to/your/laravel/project
    
  2. Run the Queue Worker Command to Test:

     php artisan queue:work --queue=high,default,low
    

    Replace high,default,low with your specific queue names.

  3. If Successful, Configure Supervisor for Continuous Running.


Step 3: Configure Supervisor

  1. Create a Configuration File for Supervisor:

     sudo nano /etc/supervisor/conf.d/laravel-worker.conf
    
  2. Add 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.log
    

    or

[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
  1. 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

  1. Reload Supervisor to Apply Changes:

     sudo supervisorctl reread
     sudo supervisorctl update
    
          or 
     sudo supervisorctl reread
     sudo supervisorctl update
     sudo supervisorctl restart laravel-worker:
    
  2. Start the Laravel Worker:

     sudo supervisorctl start laravel-worker:*
    

Step 5: Monitor and Debug

  1. Check the Logs:

     tail -f /path/to/your/laravel/project/storage/logs/worker.log
    
  2. View Supervisor Status:

     sudo supervisorctl status
    

This setup ensures that your Laravel queues are always processed in the background, even after server restarts.

More from this blog

Mandeep Singh Blog

117 posts