DEV Community

Cover image for Install supervisor on Ubuntu to run Laravel Horizon ๐Ÿš€
DevOps Descent
DevOps Descent

Posted on • Updated on

Install supervisor on Ubuntu to run Laravel Horizon ๐Ÿš€

Assuming you are on Ubuntu 22/24 and a Laravel php v10/11 application.

Prepare your Laravel app

  • Install and configure Laravel Horizon as instructed in docs
  • Make sure you can access the Horizon dashboard like - * http://yourapp.com/horizon
  • For now; it should show status as inactive on horizon dashboard

Install redis-server (unless you already have it)

We will be using a PPA for latest version

sudo add-apt-repository -y ppa:redislabs/redis
sudo apt-get update
sudo apt-get install -y redis-server
Enter fullscreen mode Exit fullscreen mode

Test if redis-server is working, run

redis-cli
Enter fullscreen mode Exit fullscreen mode

Type ping and hit enter and you will receive PONG in response

Type exit and hit enter to exit from the CLI

Update your Laravel application .env file like this -

QUEUE_CONNECTION=redis
Enter fullscreen mode Exit fullscreen mode

Configure redis server

To make redis-server auto start upon machine reboot,
Edit this file with sudo nano /etc/redis/redis.conf.
Find supervised section and update its value from auto to systemd
Save and exit the conf file.

Now enable the service with this command:

sudo systemctl enable --now redis-server
Enter fullscreen mode Exit fullscreen mode

We are good now with redis server.

Install supervisor

sudo apt install supervisor
sudo service supervisor restart
sudo systemctl enable supervisor
Enter fullscreen mode Exit fullscreen mode

Create supervisor config file for Horizon.

Supervisor keeps its programs' individual files in /etc/supervisor/conf.d

Create a fresh config file for your Laravel application

sudo nano /etc/supervisor/conf.d/laravel-app.conf
Enter fullscreen mode Exit fullscreen mode

and paste these lines into nano editor

program:laravel_horizon]
process_name=%(program_name)s_%(process_num)02d
command=php /home/ubuntu/your-project-folder/artisan horizon

autostart=true
autorestart=true
redirect_stderr=true
user=www-data

stdout_logfile=/home/ubuntu/your-project-folder/storage/horizon.log
stdout_logfile_maxbytes=10MB
logfile_backups=14
stopwaitsecs=3600
Enter fullscreen mode Exit fullscreen mode

You need to update your-project-folder path in file above
Make sure your project's storage folder is writable by www-data (apache) user (same as your web server user).

Save the config file and exit nano.

Now run these commands one by one -

sudo supervisorctl reread
sudo supervisorctl update
Enter fullscreen mode Exit fullscreen mode

Check if our horizon process is running

sudo supervisorctl
Enter fullscreen mode Exit fullscreen mode

You will see process name with status RUNNING, if not; it means you have misconfigured something.

Access your horizon dashboard at http://yourapp.com/horizon, you can see status as active on dashboard.

You can also check horizon status with command

php artisan horizon:status
Enter fullscreen mode Exit fullscreen mode

Make sure to run these commands after each new deployment

php artisan horizon:terminate
php artisan horizon:purge
php artisan queue:restart
Enter fullscreen mode Exit fullscreen mode

If you face any issue, you can restart supervisor service

sudo service supervisor restart
Enter fullscreen mode Exit fullscreen mode

OR - You can restart specific program

sudo supervisorctl restart laravel_horizon
Enter fullscreen mode Exit fullscreen mode

Similar resources

Support if you found this helpful๐Ÿ˜‰

No Money ๐Ÿ™…๐Ÿปโ€โ™€๏ธ just Subscribe to my YouTube channel.

Linktree Profile: https://linktr.ee/DevOps_Descent
GitHub: https://github.com/devopsdescent

Top comments (0)