'Laravel Horizon internal server error on 'horizon/api/*'

I tried to implement Horizon, from the terminal when I run commands like php artisan horizon:status or php artisan horizon:list I get positive feedbacks, everything seems to work just fine, but when I try to go to the /horizon view, no matter how many jobs I tried to run, in the dashboard I get this.

If I open the console from the browser I get Failed to load resource: the server responded with a status of 500 (Internal Server Error) on all the API calls like api/masters, api/stats or api/workload. Searching online I found a lot of people saying to fix the .env file or the configuration files like queue.php or horizon.php, but after following their instructions my problem persists

.env:

CACHE_DRIVER=file
QUEUE_CONNECTION=redis
SESSION_DRIVER=file
SESSION_LIFETIME=120

APP_ENV=local
APP_DEBUG=true
LOG_CHANNEL=stack
DB_CONNECTION=mysql

# Redis
REDIS_CLIENT=predis
REDIS_HOST=127.0.0.1
REDIS_PASSWORD=null

queue.php:

<php?
return [

'default' => env('QUEUE_CONNECTION', 'redis'),

'connections' => [

    'sync' => [
        'driver' => 'sync',
    ],

    'database' => [
        'driver' => 'database',
        'table' => 'jobs',
        'queue' => 'default',
        'retry_after' => 90,
    ],

    'beanstalkd' => [
        'driver' => 'beanstalkd',
        'host' => 'localhost',
        'queue' => 'default',
        'retry_after' => 90,
        'block_for' => 0,
    ],

    'sqs' => [
        'driver' => 'sqs',
        'key' => env('AWS_ACCESS_KEY_ID'),
        'secret' => env('AWS_SECRET_ACCESS_KEY'),
        'prefix' => env('SQS_PREFIX', 'https://sqs.us-east-1.amazonaws.com/your-account-id'),
        'queue' => env('SQS_QUEUE', 'your-queue-name'),
        'region' => env('AWS_DEFAULT_REGION', 'us-east-1'),
    ],

    'redis' => [
        'driver' => 'redis',
        'connection' => 'default',
        'queue' => env('REDIS_QUEUE', 'default'),
        'retry_after' => 90,
        'block_for' => null,
    ],

],

'failed' => [
    'driver' => env('QUEUE_FAILED_DRIVER', 'database'),
    'database' => env('DB_CONNECTION', 'mysql'),
    'table' => 'failed_jobs',
],
];

horizon.php:

<?php

use Illuminate\Support\Str;

return [

'domain' => env('HORIZON_DOMAIN'),

'path' => env('HORIZON_PATH', 'horizon'),

'use' => 'default',

'prefix' => env(
    'HORIZON_PREFIX',
    Str::slug(env('APP_NAME', 'laravel'), '_').'_horizon:'
),

'middleware' => ['web'],

'waits' => [
    'redis:default' => 60,
],

'trim' => [
    'recent' => 60,
    'pending' => 60,
    'completed' => 60,
    'recent_failed' => 10080,
    'failed' => 10080,
    'monitored' => 10080,
],

'metrics' => [
    'trim_snapshots' => [
        'job' => 24,
        'queue' => 24,
    ],
],

'fast_termination' => false,

'memory_limit' => 64,

'defaults' => [
    'supervisor-1' => [
        'connection' => 'redis',
        'queue' => ['default'],
        'balance' => 'auto',
        'maxProcesses' => 1,
        'maxTime' => 0,
        'maxJobs' => 0,
        'memory' => 128,
        'tries' => 1,
        'timeout' => 60,
        'nice' => 0,
    ],
],

'environments' => [
    'production' => [
        'supervisor-1' => [
            'maxProcesses' => 10,
            'balanceMaxShift' => 1,
            'balanceCooldown' => 3,
        ],
    ],

    'local' => [
        'supervisor-1' => [
            'maxProcesses' => 3,
        ],
    ],
],
];


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source