Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

myregistration's avatar

How configure Supervisord for Horizon and Reverb via Sail?

I'm using Laravel's Sail and tryin to set up Supervisord, Horizon, and Reverb for queues and websockets. How do I set the user for Horizon's program entry in Supervisord.conf? I'm not using Forge, so Laravel's documentation example user=forge will not work for me. I'm also going to use Reverb so will need to set up a Supervisor entry for that as well. I already have the entries with commands for both Horizon and Reverb, but need to know how to set the user. The example I found for Reverb uses a variable named ENV_SUPERVISOR_PHP_USER. Do I need to set an environment variable in the docker-compose.yml file? Do I use user=%(ENV_SUPERVISOR_PHP_USER)s for all of the entries in Supervisord .conf? Or should I hard code it to www-data? Where is ENV_SUPERVISOR_PHP_USER set? If you notice anything else wrong please let me know. Thanks

[supervisord]
nodaemon=true
user=root
logfile=/var/log/supervisor/supervisord.log
pidfile=/var/run/supervisord.pid

[program:php]
command=%(ENV_SUPERVISOR_PHP_COMMAND)s
user=%(ENV_SUPERVISOR_PHP_USER)s
environment=LARAVEL_SAIL="1"
stdout_logfile=/dev/stdout
stdout_logfile_maxbytes=0
stderr_logfile=/dev/stderr
stderr_logfile_maxbytes=0

[program:cron]
command=/usr/sbin/cron -f -l 8
autostart=true
stdout_logfile=/var/log/cron.out.log
stderr_logfile=/var/log/cron.err.log

[program:reverb]
command=php /var/www/html/artisan reverb:start --host="0.0.0.0" --port=8080
autostart=true
autorestart=true
user=%(ENV_SUPERVISOR_PHP_USER)s
redirect_stderr=true
stdout_logfile=/var/www/html/storage/logs/reverb.log

[program:horizon]
command=php /var/www/html/artisan horizon
autostart=true
autorestart=true
user=%(ENV_SUPERVISOR_PHP_USER)s
redirect_stderr=true
stdout_logfile=/var/www/html/storage/logs/horizon.log
``
0 likes
1 reply
LaryAI's avatar
Level 58

To configure Supervisord for Laravel Horizon and Reverb in a Docker environment managed by Laravel Sail, you need to ensure that the user specified in the Supervisord configuration has the appropriate permissions to execute the Laravel commands and manage processes within the Docker container. Typically, the user www-data is used in Docker containers for web applications since it is the default user for many web servers, including Apache and Nginx, which are commonly used with PHP applications.

Here's how you can configure your Supervisord.conf for both Horizon and Reverb:

  1. Setting the User: Since you are not using Forge, and are within a Docker environment managed by Laravel Sail, you can use www-data as the user for both Horizon and Reverb. This is generally safe and avoids permission issues, especially when dealing with file writing in Laravel (like logs and cache).

  2. Environment Variables: If you prefer to use an environment variable to set the user, you can indeed set ENV_SUPERVISOR_PHP_USER in your docker-compose.yml file. This allows you to keep your configuration flexible and environment-specific without hardcoding values in your Supervisord.conf.

Here's how you can modify your docker-compose.yml to include the ENV_SUPERVISOR_PHP_USER environment variable:

services:
  laravel.test:
    image: 'laravel/sail:latest'
    environment:
      ENV_SUPERVISOR_PHP_USER: www-data
    volumes:
      - '.:/var/www/html'

And in your Supervisord.conf, you can reference this environment variable as you have shown:

[program:horizon]
command=php /var/www/html/artisan horizon
autostart=true
autorestart=true
user=%(ENV_SUPERVISOR_PHP_USER)s
redirect_stderr=true
stdout_logfile=/var/www/html/storage/logs/horizon.log

[program:reverb]
command=php /var/www/html/artisan reverb:start --host="0.0.0.0" --port=8080
autostart=true
autorestart=true
user=%(ENV_SUPERVISOR_PHP_USER)s
redirect_stderr=true
stdout_logfile=/var/www/html/storage/logs/reverb.log

This setup ensures that both Horizon and Reverb run under the www-data user, or whichever user you specify in your Docker environment variables, maintaining flexibility and security.

Additional Notes:

  • Ensure that the user specified (e.g., www-data) has the necessary permissions to execute the commands and write to the necessary directories.
  • Always test your configuration in a development environment before deploying to production to avoid downtime caused by configuration errors.

This approach should help you effectively manage your Laravel Horizon and Reverb processes with Supervisord in a Docker environment using Laravel Sail.

Please or to participate in this conversation.