Introduction

In various VPS setups, it’s common for developers to run several long-running applications persistently. For instance, these might include small shell scripts, Node.js apps, or large web applications such as Laravel. While some external packages come with ready-to-use systemd unit files or Docker images for simple process management, others may not provide such support. Moreover, working directly with low-level init systems or container engines isn’t always the most user-friendly approach.

In such cases, Supervisor serves as a lightweight and effective process manager that simplifies the management of long-running processes. Supervisor provides a unified interface for configuring, running, and monitoring multiple applications, including features like a web-based interface and automatic error handling to simplify process management.

In this guide, we will cover how to install Supervisor on an Ubuntu server and demonstrate how to set up a Laravel application in a production environment using Supervisor. The steps include installing dependencies, setting up Supervisor configurations, and ensuring the application runs reliably.

Advantages of Using Supervisor:

  1. Ease of Configuration: Supervisor’s configuration files are more straightforward and readable compared to systemd unit files.
  2. Centralized Process Management: It provides a single interface to manage and monitor various processes.
  3. Automatic Restart: Supervisor can automatically restart processes if they crash, improving uptime.
  4. Lightweight Alternative: For those who do not want to use containers like Docker, Supervisor offers a simpler and less resource-intensive approach.

Limitations of Using Supervisor:

  1. Lack of Strong Isolation: Unlike containers, Supervisor does not provide process isolation. All processes share the same environment and resources.
  2. Limited Dependency Management: Supervisor handles processes but does not manage complex dependencies or orchestrations between services.
  3. Less Suitable for Large-Scale Architectures: In projects with numerous microservices, more robust solutions like Kubernetes or Docker Compose may be more appropriate.

When to Use Supervisor in Production:

Supervisor is a practical choice in the following scenarios:

  • For managing small or monolithic applications where complex orchestration is unnecessary.
  • When you prefer a quick and simple process management system.
  • On VPS environments with limited resources where containerization might be too resource-heavy.

However, if your application requires strict resource isolation, dependency management, or horizontal scaling, solutions like Docker or Kubernetes are more suitable.

In the next section, we will walk through the steps to install Supervisor and configure it to run a Laravel project in a production environment.

Prerequisites:

To follow this guide, you need a Linux server and a non-root user with sudo privileges. You can refer to the “Initial Server Setup Guide” for Ubuntu 20.04 for more details on how to create such a user.

Step 1: Update the Package Source and Install Supervisor

Before installing Supervisor, you need to update the package source. Then, install Supervisor using the package manager. To simplify this, you can chain the commands with && and run them in the terminal:

sudo apt update && sudo apt install supervisor

This will ensure your package list is updated and the latest version of Supervisor is installed in one step.

In the end, you should see an output similar to the following image displayed in the terminal.

After running this command, Supervisor will automatically start running. You can check its status on the system using the following command:

sudo systemctl status supervisor

you should see an output similar to the following image displayed in the terminal.

 supervisor.service - Supervisor process control system for UNIX
     Loaded: loaded (/lib/systemd/system/supervisor.service; enabled; vendor preset: enabled)
     Active: active (running) since Wed 2025-01-08 22:01:49 UTC; 4min 2s ago
       Docs: http://supervisord.org
   Main PID: 16144 (supervisord)
      Tasks: 1 (limit: 9250)
     Memory: 19.3M
        CPU: 258ms
     CGroup: /system.slice/supervisor.service
             └─16144 /usr/bin/python3 /usr/bin/supervisord -n -c /etc/supervisor/supervisord.conf

Jan 08 22:01:49 server-91-107-250-146 systemd[1]: Started Supervisor process control system for UNIX.
Jan 08 22:01:49 server-91-107-250-146 supervisord[16144]: 2025-01-08 22:01:49,445 WARN No file matches via include "/etc/supervisor/conf.d/*.conf"
Jan 08 22:01:49 server-91-107-250-146 supervisord[16144]: 2025-01-08 22:01:49,447 INFO RPC interface 'supervisor' initialized
Jan 08 22:01:49 server-91-107-250-146 supervisord[16144]: 2025-01-08 visord started with pid 16144

Categorized in:

Server,

Tagged in:

, ,