Hosting + Ai Website Builder + Free Domain (3 Month Free Credit)
Shop Today

Laravel Horizon Installation & Setup — Step-by-Step Guide

Laravel Horizon is a tool developed by Laravel that helps you manage and monitor background jobs, also known as tasks that run in the background of your app, such as sending emails or processing images.

Example:

You run a busy online store. When a customer places an order:

You don’t want to slow down the website vps while sending confirmation emails or generating invoices.

So, you queue these tasks (like placing them in a “To-Do” basket for your app).

That’s where Laravel Queues come in — and Horizon helps you control and keep an eye on those queues.

Laravel Horizon

Before we get started, make sure your app meets the following requirements:

  • Laravel 8 or above
  • Redis is installed and configured
  • PHP 8.0 or higher
  • Composer installed

Login to your YouStable VMs where you want to install Laravel Horizon and proceed with these simple commands and complete the installation. Once you have completed the proper installation, ensure that you reboot your machine to apply the changes.

composer require laravel/horizon

After installation, publish Horizon’s assets:

php artisan horizon:install

Then run migrations to set up the tables used by Horizon:

php artisan migrate

Now that you have successfully installed Horizon into your app, we need to configure it so that it can start working with the application.

Configuring Horizon with your Application

Now you need to check and ensure that your .env file has the correct queue connections defined

QUEUE_CONNECTION=redis

In config/horizon.php You can customise various settings. For example, to define supervisor configurations:

'environments' => [
    'production' => [
        'supervisor-1' => [
            'connection' => 'redis',
            'queue' => ['default'],
            'balance' => 'auto',
            'processes' => 10,
            'tries' => 3,
        ],
    ],
    'local' => [
        'supervisor-1' => [
            'connection' => 'redis',
            'queue' => ['default'],
            'balance' => 'simple',
            'processes' => 3,
            'tries' => 1,
        ],
    ],
],
Laravel Horizon Installation

Running Horizon

You can easily start Horizon using the Artisan command.

php artisan horizon

Access the Horizon dashboard at:

https://your-domain/horizon

The dashboard provides real-time insights into your queues, jobs, and workers.

Laravel Horizon offers a powerful and elegant way to manage your queues. With real-time monitoring, detailed metrics, and easy configuration, it’s an essential tool for any Laravel application utilising queues.

YouStable

Power up your business website with YouStable India’s affordable unlimited web hosting services and meet your online success! YouStable is not just a brand that provides hosting services to clients. The quality of services a customer gets from us is unparalleled and our clients know it.

Leave a Comment

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

Scroll to Top