Reputation: 3
So I have been trying to get an connection my database with homestead, but everytime I make a DB select statement I get an SQLSTATE[HY000] [2002] Connection refused. It seems like my problem is not the same as the others with the same title. I am using homestead with virtual box
Here is my select statement:
<?php
echo DB::select('select * from bruger where id = 1')
?>;
This is simply to check if I can get any info out.
I have tried various things in both my .env file and and database.php
This is what they are looking like currently:
'mysql' => [
'driver' => 'mysql',
'host' => env('DB_HOST', 'localhost'),
'port' => env('DB_PORT', 'localhost'),
'database' => env('DB_DATABASE', 'forge'),
'username' => env('DB_USERNAME', 'forge'),
'password' => env('DB_PASSWORD', ''),
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',
'strict' => false,
'engine' => null,
],
and
APP_ENV=local
APP_DEBUG=true
APP_KEY=randomKey
APP_URL=http://localhost
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=33060
DB_DATABASE=phpDatabase
DB_USERNAME=homestead
DB_PASSWORD=secret
CACHE_DRIVER=file
SESSION_DRIVER=file
QUEUE_DRIVER=sync
REDIS_HOST=127.0.0.1
REDIS_PASSWORD=secret
REDIS_PORT=33060
MAIL_DRIVER=smtp
MAIL_HOST=mailtrap.io
MAIL_PORT=2525
MAIL_USERNAME=null
MAIL_PASSWORD=null
MAIL_ENCRYPTION=null
Upvotes: 0
Views: 6514
Reputation: 9771
The port should be 3306, since you are accessing from within the homestead machine, if I understood correctly.
In fact, check the documentation
You will use the default 3306 and 5432 ports in your Laravel database configuration file since Laravel is running within the virtual machine.
Upvotes: 0
Reputation: 150
For DB_HOST and DB_PORT try using the IP and port as set in the Homestead.yaml file.
Default:
DB_HOST=192.168.10.10
DB_PORT=3306
Upvotes: 1