devinfd's avatar
Level 13

How to use Forge worker server with Horizon?

I'm trying to understand how to use and deploy to a Forge worker server (https://forge.laravel.com/docs/1.0/servers/types.html#worker-servers). Does laravel need to be deployed onto the server so php artisan:horizon can run? If not how does it work?

0 likes
4 replies
Braunson's avatar

Yes these servers need a copy of your app instance to run the jobs on, but they are specifically for the workers . So to answer your question yes it needs a copy of your app running so you can run php artisan horizon running as a Daemon on the Worker server.

Breakdown of a setup of a production server

For example if I have an app I'll have 2 servers broken down like this:

  1. Public facing server that serves the app to my users
  2. Worker Server (Has workers running specific queues)

When deploying new code I'll deploy to both servers since the queue server needs to be running the same code as the public facing server.

My deploy script would look something like this: Notice that I do a horizon:purge, horizon:terminate and queue:restart

cd /home/forge/myapp.com # update your app's path here
php artisan down
git fetch
git pull origin production # update your prod branch here
composer install --no-interaction --prefer-dist --optimize-autoloader
sudo -S service php8.x-fpm reload # update your PHP version here
composer dump-autoload
php artisan migrate --force
php artisan horizon:purge
php artisan horizon:terminate
php artisan queue:restart
php artisan up

On my public facing server I have no queue workers or daemons setup in Forge. However on my Worker server I have php artisan horizon running as a Daemon for the path of my project running as the user forge running as 1 process. Next on the Worker server, I have my app code running with the same deploy script as above but I on the queue tab I have two Active Workers setup for different queue's.

Hope this helps.

2 likes
devinfd's avatar
Level 13

Brillant, makes perfect sense. Thanks so much!

adampatterson's avatar

I'm trying to setup a worker server and the fact that it doesn't have Redis installed is throwing me for a loop.

I have a cache server, and my app servers can communicate with it just fine. I toggled Horizon and it turns on but has an error.

RedisException 
Connection timed out
# redis-cli
Command 'redis-cli' not found, but can be installed with:
apt install redis-tools

Am I missing something here?

1 like
adampatterson's avatar

Needed to enable the private network between cache and the worker server.

Please or to participate in this conversation.