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

elo's avatar
Level 3

Supervisord breaking Laravel application

I have a laravel 9 application that I want to deploy to AWS ECS. The application uses redis for queue and I have installed horizon. I also installed Supervisor in the docker container but once I deploy my application and start up supervisor in my startup.sh script, my app is never reachable and I notice that both queue worker and horizon start and then exit.

Here's the dockerfile I am working with

FROM php:8.1.4-fpm-alpine3.14

RUN apk update

RUN apk add --no-cache git libzip-dev zip unzip php8-exif supervisor

RUN mkdir -p /usr/src/php/ext/redis; \
    curl -fsSL https://pecl.php.net/get/redis --ipv4 | tar xvz -C "/usr/src/php/ext/redis" --strip 1; \
    docker-php-ext-install redis;

RUN docker-php-ext-configure pcntl --enable-pcntl \
    && docker-php-ext-install \
    pcntl

RUN docker-php-ext-install pdo pdo_mysql zip exif \
    && curl -sS https://getcomposer.org/installer | php -- \
    --install-dir=/usr/local/bin --filename=composer

WORKDIR /var/www/html

COPY supervisord.conf /etc/supervisor/conf.d/supervisord.conf

COPY . .

RUN chown -R www-data:www-data /var/www/html

RUN composer install --ignore-platform-req=ext-pcntl

RUN chmod 544 startup.sh

ENTRYPOINT ["./startup.sh"]

this is my supervisord.conf file content

[supervisord]
nodaemon=true
loglevel=debug
logfile=/var/www/html/storage/logs/supervisord.log
user=root

[program:laravel-worker]
process_name=%(program_name)s_%(process_num)02d
command=php /var/www/html/artisan queue:work redis --sleep=3 --tries=3 --max-time=3600
autostart=true
autorestart=true
stopasgroup=true
killasgroup=true
user=root
numprocs=8
redirect_stderr=true
stdout_logfile=/var/www/html/storage/logs/worker.log
stopwaitsecs=3600

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

and my startup.sh script content is

#!/bin/sh

/usr/bin/supervisord

php artisan migrate
php artisan db:seed

php artisan config:cache
php artisan route:cache

php artisan serve --host=0.0.0.0 --port 80

If I comment out /usr/bin/supervisord and deploy to aws ecs, I am able to reach my app again. So what exactly am I doing wrong with the supervisor that is causing it to break my app and how can I fix it?

0 likes
3 replies
bobbybouwmann's avatar

First of all, you shouldn't combine queue:work and horizon at the same time. You need to pick one of them and let that handle the queue. Otherwise, they might get jobs from the same queue that causes errors.

When working with Docker you want to keep your containers as small as possible. For a queue, you would either use an external service or a separated container that would run horzion. It shouldn't be running in the same container as your website because then you're running multiple processes at once. If you want that, you shouldn't use docker and just run a normal server.

1 like
elo's avatar
Level 3

@bobbybouwmann thanks for point it out the need to have separate containers. At the moment I am using AWS ECS and have one container for the app and another one for redis. So do you advice I have an app, redis, horizon containers; then use supervisor inside of the horizon container only for horizon

Please or to participate in this conversation.