I recently had to install Supervisor on an Amazon Linux 2, EC2 webserver and it didn’t seem to be as straight forward as the Laravel docs made out, so I thought I’d leave some notes here for future reference and to perhaps save somebody else a few hours trial and error.

Here are the commands I ended up running with the relevant config files I needed to create to install Pip, to install Supervisor, create the supervisor config file, laravel worker config file, then define it as a service which I could manage with a systemctl command. It was also important that Supervisor loaded automatically when the server booted up.

Some guides suggest installing Supervisor with easy_install, however I found this didn’t work so well so I ended up first installing Pip, then using this to install Supervisor. In hindsight it might be that other factors were causing Supervisor to not start, but this is the route I finally found worked, so that’s what I’m documenting here.

> sudo yum install pip


> sudo pip install supervisor


Next you need to create the supervisor config files. I kind of expected these to be created for me, but I think this was probably the main cause of my issues. Neither the config files nor logging locations are created for you when you install Supervisor, atleast they weren’t when I installed it. So that’s what we need to do next.

> sudo vi /etc/supervisor/supervisord.conf


; supervisor config file[unix_http_server]file=/var/run/supervisor.sock ; (the path to the socket file)chmod=0700 ; sockef file mode (default 0700)[supervisord]logfile=/var/log/supervisor/supervisord.log ; (main log file;default $CWD/supervisord.log)pidfile=/var/run/supervisord.pid ; (supervisord pidfile;default supervisord.pid)childlogdir=/var/log/supervisor ; ('AUTO' child log dir, default $TEMP)[rpcinterface:supervisor]supervisor.rpcinterface_factory = supervisor.rpcinterface:make_main_rpcinterface[supervisorctl]serverurl=unix:///var/run/supervisor.sock ; use a unix:// URL for a unix socket[include]files = /etc/supervisor/conf.d/*.conf


I’ve highlighted above, the paths that need to exist/be created for easy reference.

Now create your laravel-worker config file. This could just be in the file above, but it seems neater to keep it in it’s own file.

> sudo vi /etc/supervisor/conf.d/laravel-worker.conf


[program:laravel-worker]process_name=%(program_name)s_%(process_num)02dcommand=php /var/www/artisan queue:work --sleep=3 --tries=10 --max-time=36000autostart=trueautorestart=trueuser=apachenumprocs=1redirect_stderr=truestdout_logfile=/var/www/storage/logs/worker.logstopwaitsecs=3600


The highlighted bits again show you the location of artisan and your storage folder, if these differ for you you’ll need to change these. It’s also important to make sure the user is correct; I’m using apache.

Next create the service:

> sudo vi /lib/systemd/system/supervisord.service


[Unit]Description=Supervisor process control system for UNIXDocumentation=http://supervisord.orgAfter=network.target[Service]ExecStart=/usr/bin/supervisord -n -c /etc/supervisor/supervisord.confExecStop=/usr/bin/supervisorctl $OPTIONS shutdownExecReload=/usr/bin/supervisorctl -c /etc/supervisor/supervisord.conf $OPTIONS reloadKillMode=processRestart=on-failureRestartSec=50s[Install]WantedBy=multi-user.target


Again, a couple of paths to check and confirm there which might be different for you. But these are pretty standard install locations I believe. You can see where things are installed by typing:

> which supervisord


Create the all important log directory, without this Supervisor will fail to start:

> sudo mkdir /var/log/supervisor/


To get everything running and check the status:

> sudo systemctl start supervisord> sudo systemctl status supervisord> sudo systemctl enable supervisord


You should see the service is running now, but you can double check by looking for the Supervisor and PHP processes to be sure:

> ps -deaf | grep supervisor> ps -deaf | grep php


Now enable the service to automatically run on reboot. This was important for me as the webservers are generated in an auto-scaling group, so can be spun up automatically. Therefore we need Supervisor to be running straight away automatically.

> sudo chkconfig supervisord on


Hopefully that’s useful and still works for a little while yet, until everything changes again!