Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Rockblings's avatar

Laravel forge referencing wrong database connection

In forge, failed jobs are trying to insert the failed job using the wrong database connection. I’m using MySQL but it was trying to insert into sql lite. Then it throws an exception since it can’t find the path to the file. I have MySQL as both database connection and have specifically set MySQL as my job connection. I have ran php artisan cache::clear, config:clear. That didn’t help. I’m unable to recreate the issue in dev. Any help would be appreciated

0 likes
5 replies
Snapey's avatar

run the command artisan db:show and check Laravel when booted from the CLI is reading the .env file.

Report the permissions and file ownership of the .env file.

Rockblings's avatar

@Snapey Thanks for you response. i have ran the command you suggested. it shows the database connection is MYSQL: MySQL ..................................................................................................................................... 8.0.35
Connection ................................................................................................................................. mysql

Here is the .env permission and ownership: -rw-rw-r-- 1 forge forge 2276 Sep 26 08:54 .env

Snapey's avatar

nothing wrong there unfortunately

LaryAI's avatar
Level 58

It sounds like your Laravel application is defaulting to the SQLite connection for your failed jobs table. This can happen if the configuration for the queue or database is not set correctly. Here are a few steps to troubleshoot and resolve this issue:

  1. Check your .env file: Ensure that your .env file has the correct database connection settings. Specifically, check the DB_CONNECTION and QUEUE_CONNECTION variables.

    DB_CONNECTION=mysql
    QUEUE_CONNECTION=database
    
  2. Check your config/database.php file: Make sure that the default connection is set to MySQL and that the MySQL connection settings are correct.

    'default' => env('DB_CONNECTION', 'mysql'),
    
    'connections' => [
        'mysql' => [
            'driver' => 'mysql',
            'host' => env('DB_HOST', '127.0.0.1'),
            'port' => env('DB_PORT', '3306'),
            'database' => env('DB_DATABASE', 'forge'),
            'username' => env('DB_USERNAME', 'forge'),
            'password' => env('DB_PASSWORD', ''),
            'unix_socket' => env('DB_SOCKET', ''),
            'charset' => 'utf8mb4',
            'collation' => 'utf8mb4_unicode_ci',
            'prefix' => '',
            'strict' => true,
            'engine' => null,
        ],
    ],
    
  3. Check your config/queue.php file: Ensure that the failed configuration is set to use the MySQL connection.

    'failed' => [
        'driver' => env('QUEUE_FAILED_DRIVER', 'database'),
        'database' => env('DB_CONNECTION', 'mysql'),
        'table' => 'failed_jobs',
    ],
    
  4. Clear the configuration cache: Since you mentioned you already ran php artisan config:clear, also try clearing the cache and restarting the queue workers.

    php artisan cache:clear
    php artisan config:clear
    php artisan queue:restart
    
  5. Check your queue worker configuration: If you are using Supervisor to manage your queue workers, ensure that the configuration file for Supervisor is correctly set up to use the right environment variables.

    Example Supervisor configuration (/etc/supervisor/conf.d/laravel-worker.conf):

    [program:laravel-worker]
    process_name=%(program_name)s_%(process_num)02d
    command=php /path/to/your/project/artisan queue:work --sleep=3 --tries=3 --timeout=90
    autostart=true
    autorestart=true
    user=your-username
    numprocs=1
    redirect_stderr=true
    stdout_logfile=/path/to/your/project/worker.log
    
  6. Check for environment-specific configurations: Ensure that there are no environment-specific configurations that might be overriding your settings. For example, check if there are any .env.production or .env.staging files that might be used in your Forge environment.

By following these steps, you should be able to ensure that your Laravel application uses the correct MySQL database connection for failed jobs. If the issue persists, double-check all configurations and consider restarting your server to ensure all changes take effect.

Zephni's avatar

Has this still not been fixed? I'm experiencing this now. Surely it should use the environment setting here?

Please or to participate in this conversation.