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

Qun's avatar
Level 1

Make:auth logging in connection refused to MySQL DB

Hey Guys,

I'm new tot Laravel, and I'm trying out some stuff. Currently I'm watching Laravel 5.4 From Scratch, and I'm trying to use artisan make:auth. After using the command it creates the views, etc.

But when I'm trying to connect to the DB it gives the following error.

PDOException in Connector.php line 68:
SQLSTATE[HY000] [2002] No connection could be made because the target machine actively refused it.

I'm tunneling the remote DB to my localhost. I also configured my .env file

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=4444  
DB_DATABASE=DBname
DB_USERNAME=Username
DB_PASSWORD=Key

I forward the DB to port 4444. FYI I'm using XAMPP to create a localhost as server and run my Laravel project on it.

The weird thing is that the details of the error are.

in Connector.php line 68
at PDO->__construct('mysql:host=127.0.0.1;port=3306;dbname=blog', 'root', '', array(0, 2, 0, false, false)) in Connector.php line 68
at Connector->createPdoConnection('mysql:host=127.0.0.1;port=3306;dbname=blog', 'root', '', array(0, 2, 0, false, false)) in Connector.php line 43
at Connector->createConnection('mysql:host=127.0.0.1;port=3306;dbname=blog', array('driver' => 'mysql', 'host' => '127.0.0.1', 'port' => '3306', 'database' => 'blog', 'username' => 'root', 'password' => '', 'charset' => 'utf8mb4', 'collation' => 'utf8mb4_unicode_ci', 'prefix' => '', 'strict' => true, 'engine' => null, 'name' => 'mysql'), array(0, 2, 0, false, false)) in MySqlConnector.php line 24
at MySqlConnector->connect(array('driver' => 'mysql', 'host' => '127.0.0.1', 'port' => '3306', 'database' => 'blog', 'username' => 'root', 'password' => '', 'charset' => 'utf8mb4', 'collation' => 'utf8mb4_unicode_ci', 'prefix' => '', 'strict' => true, 'engine' => null, 'name' => 'mysql')) in ConnectionFactory.php line 183

I don't get why it uses 'mysql', 'host' => '127.0.0.1', 'port' => '3306', 'database' => 'blog', 'username' => 'root', 'password' => ''.

The connection works when i use artisan to insert data to the database. Could it be because of XAMPP ? Am I doing something wrong with Laravel ?

0 likes
5 replies
devit.gg's avatar

if you are using default xamp user/pass remove the "." from password, there isnt one, its just blank with username "root"

Qun's avatar
Level 1

This didn't do the trick. The problem is that im tunneling to the database and I am not connecting to the DB provided by Xampp. I don't get why Laravel even uses this information from xampp, since I already specifiek the DB in the .env

J_shelfwood's avatar

First of all, use three ` to put your code in code blocks, makes it easier for all of us ^^

Please show us your database.php config file.

Qun's avatar
Level 1

I use the default setting in which I've changed the host,port,dbname,username and password

    'default' => env('DB_CONNECTION', 'mysql'),
    'connections' => [

        'sqlite' => [
            'driver' => 'sqlite',
            'database' => env('DB_DATABASE', database_path('database.sqlite')),
            'prefix' => '',
        ],

        'mysql' => [
            'driver' => 'mysql',
            'host' => env('DB_HOST', '127.0.0.1'),
            'port' => env('DB_PORT', '4444'),
            'database' => env('DB_DATABASE', 'DBname'),
            'username' => env('DB_USERNAME', 'Username'),
            'password' => env('DB_PASSWORD', 'key'),
            'charset' => 'utf8mb4',
            'collation' => 'utf8mb4_unicode_ci',
            'prefix' => '',
            'strict' => true,
            'engine' => null,
        ],

        'pgsql' => [
            'driver' => 'pgsql',
            'host' => env('DB_HOST', '127.0.0.1'),
            'port' => env('DB_PORT', '5432'),
            'database' => env('DB_DATABASE', 'forge'),
            'username' => env('DB_USERNAME', 'forge'),
            'password' => env('DB_PASSWORD', ''),
            'charset' => 'utf8',
            'prefix' => '',
            'schema' => 'public',
            'sslmode' => 'prefer',
        ],

    ],
Qun's avatar
Qun
OP
Best Answer
Level 1

Hi Guys,

I solved it. I changed my MySQL port to 4444. Afterwards I restarted xampp and it worked.

Please or to participate in this conversation.