Reputation: 575
I'm having trouble connecting to the database when using Laravel Homestead. I can't really understand why it doesn't work I've tried god damn everything I guess. Now i got stuck and can't try much more and I start to interact with more people. Does stackoverflow have any good answer or advice to give me? :)
This is my settings
'mysql' => array(
'driver' => 'mysql',
'host' => $_ENV['DB_HOST'],
'database' => $_ENV['DB_NAME'],
'username' => $_ENV['DB_USERNAME'],
'password' => $_ENV['DB_PASSWORD'],
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',
'port' => '33060'
)
I've also tried this with the same response.
'mysql' => array(
'driver' => 'mysql',
'host' => $_ENV['DB_HOST'],
'database' => $_ENV['DB_NAME'],
'username' => $_ENV['DB_USERNAME'],
'password' => $_ENV['DB_PASSWORD'],
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',
'port' => '3306'
)
This is my ENV variables.
{
host: "127.0.0.1",
database: "homestead",
username: "homestead",
password: "secret"
}
The return is:
PDOException
SQLSTATE[HY000] [2003] Can't connect to MySQL server on '127.0.0.1' (111)
In both Migrations as the website.
It works to connect with Sequel Pro, it looks like this in Sequel Pro.
EDIT:Is it possible that there's some kinda collision between my VagrantBox's IP and the MAMP one? I've stopped every MAMP thing I've running but still the same issue, just wondering if I need to stop it somewhere else?
Upvotes: 1
Views: 8309
Reputation: 1608
What have you got when you open the PHP REPL by typing php artisan tinker
at the root of your project and then print_r(Config::get('database.connections')['mysql']);
?
You should have this:
Array
(
[driver] => mysql
[host] => localhost
[database] => homestead
[username] => homestead
[password] => secret
[charset] => utf8
[collation] => utf8_unicode_ci
[prefix] =>
[port] => 33060
)
If you have something different your environment variables are not good or you are not detecting the local environment.
Upvotes: 0
Reputation: 25414
You shouldn't need to specify the port at all, I'd remove that line. For host, try localhost
instead. Also make sure that Homestead uses the environment you have set your database to, most likely local
.
MAMP can't conflict with it, unless you've at some point manually set your MAMP MySQL port to 33060, which I very much doubt.
Here's a default file which works great for me:
'mysql' => array(
'driver' => 'mysql',
'host' => 'localhost',
'database' => 'mydbname',
'username' => 'homestead',
'password' => 'secret',
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',
),
Lycka till!
Upvotes: 7