Reputation: 5159
I get the following error message in the terminal when I try to execute php artisan migrate
command
SQLSTATE[HY000] [1045] Access denied for user 'homestead'@'localhost' (using password: YES)
I don't use homestead
. I have these 2 files in the root directory: .env.php
and .env.local.php
in which I keep sensitive values and values that differ between environments (development and production). So what's wrong and how to fix the problem?
Upvotes: 2
Views: 2872
Reputation: 5159
hostname
in your terminal and hit Enter key. This will let you know your hostname (Name of your computer/machine).bootstrap/start.php
file, use this line 'local' => array('put-your-hostname-here'),
instead of this line 'local' => array('homestead'),
In .env.local.php
file, save your local database configuration like this:
<?php
return array(
"DB_NAME" => "local_database_name",
"DB_USERNAME" => "local_database_username",
"DB_PASSWORD" => "local_database_password",
// any other configuration..
);
In .env.php
file, save your remote database configuration like this:
<?php
return array(
"DB_NAME" => "remote_database_name",
"DB_USERNAME" => "remote_database_username",
"DB_PASSWORD" => "remote_database_password",
// any other configuration..
);
In app/config/database.php
file, set your database connection like this:
'mysql' => array(
'driver' => 'mysql',
'host' => 'localhost',
'database' => $_ENV['DB_NAME'],
'username' => $_ENV['DB_USERNAME'],
'password' => $_ENV['DB_PASSWORD'],
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',
),
Finally, you MUST remove or disable any working code exists in app/config/local/database.php
file, otherwise the error you mentioned will be thrown.
Upvotes: 1