This guide will assist you in learning about Supervisord and how you could install it for your Laravel applications.
What is Supervisord?
Supervisord is a simple, fast worker manager, designed to monitor and control the processes which allow you to defer the processing of a time-consuming task to speed up the web requests to your application.
Supervisord is the only available Laravel apps deployed with Laravel or Custom PHP Stacks.
How to Install and Configure Laravel Supervisord on Cloudways
Step 1: Installing Supervisord
Go to Server Management, then Settings & Packages, and then access the Packages section. Click on the Install button next to Supervisord to start the installation process.
Before the process starts, you will be asked to install Redis on the server (if it is not already installed), as it is required for Laravel queues. Wait for the installation process to finish.
You can check the Supervisord service status from the Manage Services section, and also Restart the service if required.
Step 2: Supervisord Application Prerequisites
This process describes the configuration when Redis is used as the default driver. You need to configure your application to use Redis.
After installation, you need to carry out application configuration changes so that Redis could be used as the queue driver. To do that, first, it is required to install “predis/predis” package for Laravel with Composer.
Connect to server via SSH, then go to your application directory webroot (/home/master/applications/<app folder>/public_html/) and run this command:
composer require predis/predis
Once it is installed, next you need to configure it in the application. For that, edit the /home/master/applications/public_html/.env file in your application as follows:
Change From: QUEUE_DRIVER=sync
Change to: QUEUE_DRIVER=redis
Next, edit the /home/master/applications/public_html/config/queue.php file as follows:
Change From: ‘default’ => env(‘QUEUE_DRIVER’, ‘sync’),
Change To: ‘default’ => env(‘QUEUE_DRIVER’, redis’),
After these changes are saved in the Laravel application, proceed to the next step.
Step 3: Add New Job
Under Application Management, go to Application Settings and select the tab for Supervisor Jobs. Click on Add New Job button to add a job for Supervisord.
The various Laravel queue related options are briefly explained below:
Connection Driver: Redis is used as the queue driver where the jobs will be held as configured in Step 2.
Number of process: Number of processes control how many processes supervisord will run at the same time. The default value is 1.
Timeout: The timeout option specifies how long the Laravel queue master process will wait before killing off a child queue worker that is processing a job.
Sleep Time: The sleep time option determines how long the worker will “sleep” if there are no new jobs available. While sleeping, the worker will not process any new jobs – the jobs will be processed after the worker wakes up again.
Queue: The names of the queues to work.
Maximum Tries: Maximum number of tries after which the job is logged as a fail.
Environment (Optional): The environment the command should run under.
Artisan Path: Add a custom Artisan path or leave it unchanged for default.
Fill in the required details and click the Save button.
Step 4: Job Status and other options
The job status can be checked by clicking the Jobs Status button.
This will show the status of the job and other related information including uptime.
If you want to restart any job, click the icon in front of it. There is also the option of removing any job by clicking the remove icon.
You now know how to install and use Supervisord on Cloudways with your Laravel app.
You can check the job logs in the following path: /home/master/applications/<app folder>/logs/<appname_jobID>.log