Skip to content

Instantly share code, notes, and snippets.

@burnz
Forked from ankurk91/laravel_horizon.md
Created August 26, 2019 00:06
Show Gist options
  • Save burnz/77c98e3e5e73f34078024c1a1d4bb6dd to your computer and use it in GitHub Desktop.
Save burnz/77c98e3e5e73f34078024c1a1d4bb6dd to your computer and use it in GitHub Desktop.
Laravel Horizon, redis-server, supervisord on Ubuntu server

Laravel Horizon, redis-server, supervisord on Ubuntu 16/18 server

Laravel 5.8, Horizon 3.x, Redis 5.x

Parepare application

  • 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 dashbaord

Install redis-server

  • Using PPA for latest version
sudo add-apt-repository -y ppa:chris-lea/redis-server
sudo apt-get update
sudo apt-get install -y redis-server
  • Test if redis-server is working, run
redis-cli
  • Type ping and you will recieve PONG in response

  • Type exit to exit the CLI

  • Update your Laravel application .env file like this -

QUEUE_CONNECTION=redis
  • Note: other redis configurations are not need to be updated, the default host and port should work fine.
  • Configure redis server
  • To make redis-server autostart upon reboot,
  • Open file with sudo nano /etc/redis/redis.conf
  • Find supervised section and update its value from no to systemd
  • Save and exit the conf file.
  • Enable the service with this command
sudo systemctl enable redis-server.service
  • Try restarting the service now.
sudo systemctl status redis-server.service
sudo systemctl restart redis-server.service
  • We are good now.

Install supervisor

sudo apt install supervisor
sudo service supervisor restart
sudo systemctl enable supervisor

Create supervisor config 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/your-laravel-app.conf
  • 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
  • You need to update your-project-folder path in above config
  • Make sure your project storage folder is writable by www-data (apache) user
  • Save the config file and exit nano
  • Now run these commands one by one -
sudo supervisorctl reread
sudo supervisorctl update
  • Check if our horizon process is running
sudo supervisorctl
  • 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.

  • Make sure to run these commands after each new deployment

php artisan horizon:purge
php artisan horizon:terminate
  • If you face any issue, you can restart supervisor service
sudo service supervisor restart
  • OR -You can restart specific program
sudo supervisorctl restart laravel_horizon

Resources

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment