Configure Laravel Horizon on Infomaniak

Laravel Horizon is a management tool for your asynchronous tasks using redis, it allows you to monitor the correct execution of your tasks, to extract metrics about their execution and even to restart those that have failed.

This package is easy to use, but configuring it is a little less so, especially when you have to use a third-party host. We are also going to see how to configure Horizon on the Swiss host Infomaniak.

Infomaniak prerequisites:

  • A dedicated Infomaniak cloud server
  • SSH access

Laravel requirements:

  • The Laravel Horizon package installed in your application

Infomaniak configuration

The easiest way to install the packages needed to use Horizon is to go through the utility called "Fast installer" available in the management interface of your dedicated cloud server.

In this utility you will find a multitude of software and tools that can be installed on your server, but the ones that interest us are the following:

  • Say it again
  • SystemD

Redis is a high performance key-value database system and SystemD allows running processes in the background (like Laravel Horizon).

Thanks to SystemD the Horizon service will be executed and more importantly restarted in the event of a stop.

SystemD configuration file

The configuration file needed to use SystemD is very simple, you just need to specify the absolute path to your application's artisan file.

[Unit] Description=Laravel Horizon Queue Manager After=network.target auditd.service [Service] ExecStart=/usr/bin/php /home/clients/YOUR_CLIENT_ID/sites/YOUR_SITE/artisan horizon Restart=always [Install] WantedBy=multi -user.target

This file is to be stored in a folder specific to SystemD:

~/.config/systemd/user/

In this example the file created is called “horizon.service”, it can be created with Nano for example by using the command:

nano ~/.config/systemd/user/horizon.service

But how do I find the absolute path of my application?

The easiest way is to connect in SSH and go to the root of your application and execute the pwd command like this:

$ pwd // absolute path of your application /home/clients/YOUR_CLIENT_ID/sites/YOUR_SITE

Useful commands

Now that your file has been created you are ready to use Horizon but it will not run by itself, you need to authorize the configuration file and run it.

Allow configuration file

systemctl —user enable horizon

Run the configuration file

systemctl —user start horizon

Stop running the configuration file

systemctl —user stop horizon

Findings

Your Horizon should be running and it should restart if it stops, you can check that Horizon is running correctly in its control panel.

Leave a Reply

Your email address will not be published. Required fields are marked *