DEV Community

Cover image for Auto restarting Laravel Horizon on code changes
Stev Lasowski
Stev Lasowski

Posted on • Updated on

Auto restarting Laravel Horizon on code changes

I have been meaning to look into a solution for restarting Laravel Horizon on code changes for a while. Our team uses Docker for our development environment and a container will start with horizon running. However, any code changes would mean we had to restart that container before the changes would load.

That's when I looked into a solution. It turns out it was pretty simple. There is a handy node tool that will monitor files for changes and restart. I have seen it in use for simple nodejs servers. Enter nodemon

We can install it in an Ubuntu container with

apt-get update && apt-get install npm -y && npm install -g nodemon
Enter fullscreen mode Exit fullscreen mode

Now we launch our horizon with the below command

/usr/local/bin/nodemon --exec /usr/local/bin/php artisan horizon -e php
Enter fullscreen mode Exit fullscreen mode

the -e php tells nodemon to monitor all .php files and restart on a change.

Buy Me A Coffee

Top comments (0)