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:
-
Setting the User: Since you are not using Forge, and are within a Docker environment managed by Laravel Sail, you can use
www-dataas 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). -
Environment Variables: If you prefer to use an environment variable to set the user, you can indeed set
ENV_SUPERVISOR_PHP_USERin yourdocker-compose.ymlfile. This allows you to keep your configuration flexible and environment-specific without hardcoding values in yourSupervisord.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.