Setting up Laravel Supervisor on Linux: A Step-by-Step Guide

ArjunAmrutiya
2 min readDec 8, 2023

--

Introduction:
Laravel Supervisor is a powerful process monitoring tool that ensures your Laravel application’s background tasks, such as queue processing and task scheduling, run smoothly and reliably. In this guide, we’ll walk through the steps to set up Laravel Supervisor on a Linux server, enabling you to manage your Laravel application’s tasks efficiently.

Prerequisites

Before we begin, make sure you have the following:

  • A Laravel application deployed on a Linux server.
  • SSH access to your server.
  • Composer installed on your server.

Step 1: Install Supervisor

SSH into your server and install Supervisor using the package manager specific to your Linux distribution. For example, on Ubuntu, use:

sudo apt-get update
sudo apt-get install supervisor

Step 2: Configure Supervisor

Create a new Supervisor configuration file for your Laravel application:

sudo nano /etc/supervisor/conf.d/laravel-worker.conf

Add the following configuration, adjusting the paths and values as needed:

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

Step 3: Update Supervisor Configuration

After saving the configuration file, update Supervisor to read the new configuration and start the Laravel worker:

sudo supervisorctl reread
sudo supervisorctl update
sudo supervisorctl start laravel-worker:*

Step 4: Run Different Queue Job Types with Supervisor

Laravel supports multiple queue drivers, including sync, database, beanstalkd, sqs, and more. Depending on your application's requirements, adjust the queue driver in your Laravel .env file or queue configuration file.

For example, to use the database queue driver, update your .env file:

QUEUE_CONNECTION=database

Or for the sqs queue driver:

QUEUE_CONNECTION=sqs

Choose the queue driver that best suits your application’s needs.

Step 5: Restart Supervisor

Restart Supervisor to apply the changes

sudo service supervisor restart

Conclusion

Congratulations! You’ve successfully set up Laravel Supervisor on your Linux server. This enhances the reliability of your Laravel application by ensuring background tasks, including various queue job types, are managed efficiently. Monitor your logs and Supervisor dashboard to keep track of the tasks and make necessary adjustments.

By following this step-by-step guide, you’ve empowered your Laravel application with a robust process management solution, improving its overall performance and reliability.

Go forth and get more out of your content. Go forth and conquer Medium! (and while you’re at it, follow me on Medium! and feel free to Subscribe)

Found this post useful? Kindly tap the 👏 button below! :)

🌟 Enjoy my blogging content? Support my work by buying me a virtual coffee on BuyMeACoffee! Your contributions help fuel insightful tech articles. Join hands in making coding more accessible and exciting for all. https://www.buymeacoffee.com/arjunamrutiya🚀

--

--

ArjunAmrutiya

👋 Hey there! I'm Arjun Amrutiya, a passionate web developer and blogger who loves all things PHP, Laravel and Vue.js. Welcome to my Medium account!