How to set up and configure Laravel's Horizon package for managing queues?

To set up and configure Laravel's Horizon package for managing queues, follow these steps:

  1. Install the Horizon package using Composer:

    composer require laravel/horizon
  2. Publish the package's configuration files:

    php artisan vendor:publish --provider="Laravel\Horizon\HorizonServiceProvider"
  3. Create the database table required for Horizon:

    php artisan horizon:install
  4. Open the config/horizon.php configuration file and make necessary changes. You can customize options like queue prefixes, environments, monitoring options, and more.

  5. In your .env file, specify the REDIS_HOST, REDIS_PASSWORD, and REDIS_PORT variables to point to your Redis server. Horizon uses Redis as its backend, so ensure Redis is properly configured.

  6. Configure your config/queue.php file to use the Redis queue driver. Update the 'default' value to 'redis' and specify the Redis connection details.

    'default' => env('QUEUE_CONNECTION', 'redis'), 'connections' => [ 'redis' => [ 'driver' => 'redis', 'connection' => 'default', 'queue' => env('REDIS_QUEUE', 'default'), 'retry_after' => 90, 'block_for' => null, ], // Other connections... ],
  7. Start Horizon's supervisor process using the horizon Artisan command:

    php artisan horizon

    This will launch the Horizon dashboard and start processing queued jobs.

  8. If you'd like to retrieve and monitor Horizon's metrics using Horizon's dashboard, you can configure the project's /config/horizon.php file with an stripe_key and stripe_secret from your Stripe account.

These steps will help you set up and configure Laravel's Horizon package for managing queues effectively.