Using Mac OS X and Homestead 2.2.1 with Laravel 5.2.
In terminal (within homestead in my project folder) I can do php artisan to see all the available commands. When I try to run php artisan migrate I get a connection error:
SQLSTATE[HY000] [2002] Connection refused
I have setup a Laravel project with these .env settings
DB_HOST=127.0.0.1
DB_DATABASE=tcv
DB_USERNAME=homestead
DB_PASSWORD=secret
I have also tried localhost for DB_HOST and root for DB_USERNAME and DB_PASSWORD. And all possible variations of these put together!
In Sequel Pro (db management application) I CAN connect with these settings
Host 127.0.0.1
Username homestead
Password secret
Database tcv
Port 33060
But this database is obviously empty, because I cant migrate to it from terminal ...
As far as I can make out it is a configuration issue, since I can connect to it with Sequel Pro. But I have honestly no freaking idea what is setup wrong.
Thanks for the help !!
EDIT
For some reason I get the same SQLSTATE[HY000] [2002] Connection refused
error when moving my project to MAMP and running php artisan migrate.
Now I am completely lost ...
Problem
In Laravel you have
config/database.php
where all the setup for the connection is located. You also have a.env
file in the root directory in your project (which everyone uses for timesaving). This contains variables that you can use for the entire project.On a standard L5 project the MySql section of
config/database.php
looks like this:Notice there is no port set!
Although in my
.env
file I had setDB_PORT=33060
. But thatvalue (3306)
was never read into theconfig/database.php
.So don't be a dumbass like myself and forget to check the
database.php
file.FIX
Simply add
'port' => env('DB_PORT', 3306),
to your config/database.php and set that value in .env like thisDB_PORT=3306