Reputation: 1560
I moved an application that I'm working on into a new dev server, a Laravel Homestead VagrantBox on a Mac OSX host. Upon doing so, I ran php artisan:migrate to update my database and this went through without a hitch.
I decided to create a new user to continue testing, so I created the route
Route::get('/newuser', function()
{
User::create([
'username' => 'someone',
'email' => '[email protected]',
'password' => Hash::make('password')
]);
return 'Done.';
});
When I visit /newuser, however. I am getting the following message.
SQLSTATE[HY000] [2002] Connection refused
Now, I know that my database config must be correct, as I received no errors when I ran php artisan migrate and my database migrated successfully. However, just to be safe, I checked my database config.
'mysql' => array(
'driver' => 'mysql',
'host' => 'localhost:33060',
'database' => 'site',
'username' => 'root',
'password' => 'apassword',
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',
),
I figured that maybe there was an issue with the way I defined the port I was on, so I added the parameter:
'port' => '33060'
Upon doing this, the error message changed from "Connection refused" to "No such file or directory"
I'm at a loss. Does anyone have any pointers?
Upvotes: 1
Views: 2362
Reputation: 4895
I had same problem and i saw my database server was unresponsive i restarted and it works... sometime it cause when wrong configuration.
I posted this answer if someone will have same issue and mysql unresponsive :)
Upvotes: 0
Reputation: 166126
Now, I know that my database config must be correct, as I received no errors when I ran php artisan migrate
It's a better than even money bet when you're stuck on something that it's one of your assumptions that's the problem. It's possible your Laravel application is reading different credentials during a command line run, or that the migration had nothing to do, or for some weird PHP reason the errors were suppressed during your migration run. I'd check the credentials Laravel's using during the context your errors are cropping up. Add the following code to your newuser
route to see what Laravel's reading.
$default = Config::get('database.default');
var_dump($default);
$config = Config::get('database.connections.'.$default);
var_dump($config);
Upvotes: 2