Installing and Configuring Supervisor for a Laravel Application on Linux
Ronak Golakiya
Certified Laravel Developer | Project Manager | Freelance | Full Stack Developer | Server Management | AWS | ChatGPT | OpenAI
Supervisor is a powerful process control system that can help manage your Laravel application's processes. Follow these steps to install and configure Supervisor on your Linux-based system.
Step 1: Installing Supervisor
1. Open your terminal and run the following command to install Supervisor:
sudo apt-get install supervisor
2. After the installation is complete, verify that the Supervisor service is running:
service supervisor status
Step 2: Configuring Supervisor
Supervisor uses configuration files stored in the /etc/supervisor/conf.d directory. These files specify how your processes should be managed. You can create multiple configuration files within this directory for different processes.
1. Navigate to the Supervisor configuration directory:
cd /etc/supervisor/conf.d
2. Use the ls command to verify the presence of the conf.d directory:
ls
3. Create a new configuration file for your process. For example, let's create a file named laravel-queue.conf:
touch laravel-queue.conf
Step 3: Configuring a Process
Let's configure the laravel-queue.conf file to start and monitor a Laravel queue worker process.
领英推荐
1. Open the laravel-queue.conf file in your preferred text editor, such as vi:
vi laravel-queue.conf
2. Add the following configuration to the file:
[program:laravel-queue]
process_name=%(program_name)s_%(process_num)02d
command=php /home/forge/app.com/artisan queue:work database --sleep=3 --tries=3
autostart=true
autorestart=true
user=forge
numprocs=2
redirect_stderr=true
stdout_logfile=/home/forge/app.com/worker.log
stopwaitsecs=3600
Note: Replace queue:work database in the command line with the queue connection you want to use, such as redis or sqs, based on your application configuration in config/queue.php.
Step 4: Starting Supervisor
After configuring your process, update Supervisor and start the new processes:
1. Run the following command to have Supervisor re-read the configuration files:
sudo supervisorctl reread
2. Update Supervisor to apply the new configuration:
sudo supervisorctl update
3. Start the configured process:
sudo supervisorctl start laravel-queue:*
By following these steps, you have successfully installed and configured Supervisor to manage your Laravel application's processes. Supervisor will ensure that your processes are automatically started and restarted as needed.