How to run Laravel Queues with Supervisor on CentOS/AlmaLinux/RockyLinux/RHEL Print

  • 0

How to run Laravel Queues with Supervisor on CentOS/AlmaLinux/RockyLinux/RHEL

You have to run this command php artisan queue:work to execute Laravel Queues, however, in a production environment you will need to handle this automatically. You can run Laravel Queues automatically and efficiently using Supervisor on your Linux machine.

 

Install Supervisor

Supervisor is a client/server system that allows its users to monitor and control a number of processes on UNIX-like operating systems. Supervisor is used with Laravel to run Queue tasks automatically.

click here for installation instructions

 

We used a cPanel server with CentOS 7.9 when we tested the commands in this article.

 


 

Configure Supervisor

1. Open Supervisor configuration file using your preferred editor:

nano /etc/supervisord.conf

 

2. Edit the following section and add it to the supervisor configuration file. 

Assuming that your linux user is myxuser and Laravel artisan file is located in /home/myxuser/laravelproject/artisan

 

[program:laravel-worker]
command=/usr/local/bin/php /home/myxuser/laravelproject/artisan queue:work --sleep=3 --tries=3    ; << CHANGE THIS - The php artisan Command    
process_name=%(program_name)s 
numprocs=1      
autostart=true  
autorestart=true  
startsecs=10    
startretries=3       
user=myxuser      ; << CHANGE THIS - Linux User
redirect_stderr=true      
stdout_logfile=/home/myxuser/laravelproject/laravel-worker.log       ; << CHANGE THIS - Log file path. The file must be created already as Supervisor will not attempt to create it

 

3. Save and close the configuration file.

 

 

4. Restart Supervisor

systemctl restart supervisord

 

5. Check Supervisor status to see if the command is running

systemctl status supervisord

 

You should find the command in the Status output

 

supervisord.service - Process Monitoring and Control Daemon
Loaded: loaded (/usr/lib/systemd/system/supervisord.service; enabled; vendor preset: disabled)
Active: active (running) since Wed 2022-01-12 10:56:15 EST; 14s ago
Process: 14042 ExecStart=/usr/bin/supervisord -c /etc/supervisord.conf (code=exited, status=0/SUCCESS)
Main PID: 14045 (supervisord)
CGroup: /system.slice/supervisord.service
├─14045 /usr/bin/python /usr/bin/supervisord -c /etc/supervisord.conf
└─14046 /opt/cpanel/ea-php74/root/usr/bin/php /home/myxuser/laravelproject/artisan queue:work --sleep=3 --tries=3

Was this answer helpful?

« Back