Step-by-Step Guide to Configure Laravel Supervisor on Linux with Redis Server

This tutorial shows you how do you Configure Laravel Supervisor on Linux with Redis Server. You can use any control panel Ex: WHM/cPanel, DirectAdmin, Plesk, etc.

Laravel Supervisor is a process control system that allows you to monitor and control processes on your Linux server. It is especially useful for managing long-running processes, such as queue workers or socket servers. By using Supervisor, you can ensure that your processes are always running, even if they crash or the server is restarted. It’s easy to install Laravel Supervisor on Linux.

To install Supervisor in Linux with Redis server, you can follow these steps:

Install Supervisor by running the following command:

CentOS:

sudo yum install supervisor

Ubuntu:

sudo apt-get install supervisor
Install Redis server by running the following command:

CentOS:

sudo yum install redis

Ubuntu:

sudo apt-get install redis
Start Redis server by running the following command:
sudo systemctl start redis
Create a Supervisor configuration file for your worker by running the following command:
sudo nano /etc/supervisord.d/worker1.ini

In this file, you can define your worker process and its configuration. The configuratin file should be ini file. You can create multiple worker ini file and define them in different name. Ex: worker1.ini, worker2.ini. Here’s an example configuration for a Laravel queue worker:

[program:laravel-worker]
process_name=%(program_name)s_%(process_num)02d
command=php /path/to/artisan queue:work redis --sleep=3 --tries=3
autostart=true
autorestart=true
user=username
numprocs=8
redirect_stderr=true
stdout_logfile=/path/to/worker.log
path:

/path/to/ replace this part by your actual project path. Where you keep your artisan and worker.log file. Ex. for cPanel: go to your domain public html foler where you keep artisan file. Your left side you can see the path. such as if your domain name is abc.com and hosting username is abccom in that case the link could be /home/abccom/public_html/
DirectAdmin and others control panel also similar and for linux project it could be /var/www/html
Another easy way to find your path is, just go to your artisan file folder and use PWD command to get path.

user:

You have to use your hosting account username here. Ex: If Domain name abc.com and the hosting account username is abccom. You have to use abccom username in user section.

This configuration will start 8 worker processes that will run the Laravel queue:work command with Redis as the queue driver. Each worker will sleep for 3 seconds between jobs and will retry failed jobs up to 3 times. The worker logs will be saved to /path/to/worker.log.

Reload the Supervisor configuration by running the following command:
sudo supervisorctl reread

This will read the updated configuration file and add the new worker process to Supervisor.

Update Supervisor to start the new worker process by running the following command:
sudo supervisorctl update

This will update Supervisor to start the new worker process defined in your configuration file.

Start the worker process by running the following command:
sudo supervisorctl start worker1:*

This will start all the processes defined in the worker1.ini configuration file.

Check the status of the worker processes by running the following command:

This will show you the status of all the Supervisor-managed processes, including your worker processes.

In summary, Laravel Supervisor is a powerful tool for managing long-running processes on your server. By configuring it correctly, you can ensure that your processes are always running and performing optimally.

YouTube channel: https://www.youtube.com/@trainbrain007