To set up and configure Laravel's Horizon package for managing queues, follow these steps:
Install the Horizon package using Composer:
composer require laravel/horizon
Publish the package's configuration files:
php artisan vendor:publish --provider="Laravel\Horizon\HorizonServiceProvider"
Create the database table required for Horizon:
php artisan horizon:install
Open the config/horizon.php
configuration file and make necessary changes. You can customize options like queue prefixes, environments, monitoring options, and more.
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.
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...
],
Start Horizon's supervisor process using the horizon
Artisan command:
php artisan horizon
This will launch the Horizon dashboard and start processing queued jobs.
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.