Skip to content
Advertisement

Laravel: SQLSTATE HY000 2002 No connection could be made because the target machine actively refused it

I am trying to migrate migrations to MySQL database using php artisan migrate in Laravel 5.2’s Homestead on my local machine. I keep getting this error:

[PDOException]

SQLSTATE[HY000] [2002] No connection could be made because the target machine 
actively refused it.

I can connect to the database just fine using MySQL workbench, but I want to use laravel’s migration feature.

My database.php looks like this:

    'mysql' => [
        'driver' => 'mysql',
        'host' => env('DB_HOST', '192.168.10.10'),
        'port' => env('DB_PORT', '33060'),
        'database' => env('DB_DATABASE', 'laraveldb'),
        'username' => env('DB_USERNAME', 'homestead'),
        'password' => env('DB_PASSWORD', 'secret'),
        'charset' => 'utf8',
        'collation' => 'utf8_unicode_ci',
        'prefix' => '',
        'strict' => false,
        'engine' => null,
    ],

Has anyone had this problem before?

Advertisement

Answer

Use these default settings in your .env file:

DB_HOST=127.0.0.1
DB_PORT=33060
DB_DATABASE=homestead
DB_USERNAME=homestead
DB_PASSWORD=secret

Also, be sure homestead database is created.

The thing is .env settings override database.php ones.

Documentation

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement