How-to's Manage queues with Laravel Horizon
1. Install the laravel/horizon package
  1. composer require laravel/horizon
2. Run the following command to publish the assets
  1. php artisan horizon:install
 INFO  Installing Horizon resources.

Service Provider ......................................................... 0.66ms DONE
Configuration ............................................................ 0.35ms DONE

 INFO  Horizon scaffolding installed successfully.
3. Update the REDIS_HOST to point to the correct host (To avoid error Predis\Connection\ConnectionException)
Predis\Connection\ConnectionException
php_network_getaddresses: getaddrinfo for redis failed: Temporary failure in name resolution [tcp://redis:6379].
.env
REDIS_HOST=127.0.0.1
4. Install Redis server package
  1. sudo apt install redis-server
5. Configure Redis to use systemd as the supervision method
/etc/redis/redis.conf
...

# If you run Redis from upstart or systemd, Redis can interact with your
# supervision tree. Options:
#   supervised no      - no supervision interaction
#   supervised upstart - signal upstart by putting Redis into SIGSTOP mode
#   supervised systemd - signal systemd by writing READY=1 to $NOTIFY_SOCKET
#   supervised auto    - detect upstart or systemd method based on
#                        UPSTART_JOB or NOTIFY_SOCKET environment variables
# Note: these supervision methods only signal "process is ready."
#       They do not enable continuous liveness pings back to your supervisor.
supervised systemd

...
6. Restart the Redis service to apply the changes
  1. sudo systemctl restart redis.service
7. Verify Redis service is active and running
  1. sudo systemctl status redis
● redis-server.service - Advanced key-value store
     Loaded: loaded (/lib/systemd/system/redis-server.service; enabled; vendor preset: enabled)
     Active: active (running) since Wed 2024-11-13 09:11:49 UTC; 13s ago
       Docs: http://redis.io/documentation,
             man:redis-server(1)
    Process: 1796508 ExecStart=/usr/bin/redis-server /etc/redis/redis.conf (code=exited, status=0/SUCCESS)
   Main PID: 1796517 (redis-server)
      Tasks: 4 (limit: 1131)
     Memory: 2.0M
     CGroup: /system.slice/redis-server.service
             └─1796517 /usr/bin/redis-server 127.0.0.1:6379

Nov 13 09:11:49 ubuntu-s-1vcpu-1gb-sgp1-01 systemd[1]: redis-server.service: Succeeded.
Nov 13 09:11:49 ubuntu-s-1vcpu-1gb-sgp1-01 systemd[1]: Stopped Advanced key-value store.
Nov 13 09:11:49 ubuntu-s-1vcpu-1gb-sgp1-01 systemd[1]: Starting Advanced key-value store...
Nov 13 09:11:49 ubuntu-s-1vcpu-1gb-sgp1-01 systemd[1]: redis-server.service: Can't open PID file /run/redis/redis-serve>
Nov 13 09:11:49 ubuntu-s-1vcpu-1gb-sgp1-01 systemd[1]: Started Advanced key-value store.
8. Test the Redis connectivity with ping command
  1. redis-cli
127.0.0.1:6379> ping
PONG
9. Install the latest version of PM2 globally
  1. npm install pm2@latest -g
10. Create a PM2 configuration file with the following content
ecosystem.config.cjs
module.exports = {
  apps : [{
    name: 'Laravel Horizon',
    script: 'php',
    args: 'artisan horizon',
  }],
}
11. Start the Laravel Horizon process with PM2
  1. pm2 start ecosystem.config.cjs
[PM2][WARN] Applications Laravel Horizon not running, starting...
[PM2] App [Laravel Horizon] launched (1 instances)
┌────┬────────────────────┬─────────────┬─────────┬─────────┬──────────┬────────┬─────────┬───────────┬──────────┬──────────┬──────────┬──────────┐
│ id │ name               │ namespace   │ version │ mode    │ pid      │ uptime │ restart │ status    │ cpu      │ mem      │ user     │ watching │
├────┼────────────────────┼─────────────┼─────────┼─────────┼──────────┼────────┼─────────┼───────────┼──────────┼──────────┼──────────┼──────────┤
│ 0  │ Laravel Horizon    │ default     │ N/A     │ fork    │ 1808674  │ 0s     │ 0       │ online    │ 0%       │ 20.5mb   │ root     │ disabled │
└────┴────────────────────┴─────────────┴─────────┴─────────┴──────────┴────────┴─────────┴───────────┴──────────┴──────────┴──────────┴──────────┘
12. Navigate to https://laravel.get-go.dev/tinker to send batch of queueable emails 13. Navigate to http://localhost/horizon and you should see the Horizon dashboard page13. Navigate to https://localhost/telescope to have more insight of the log entries, queued jobs, mail, and more