loacalhost vs127.0.0.1 in .env file in laravel
I am very new to Laravel. I am using Homestead. When I try to any migration using php artisan migrate command I have to use DB_HOST=127.0.0.1 in the .env file. If I use localhost instead of 127.0.0.1 if get the following error: [PDOException]
SQLSTATE[HY000] [1045] Access denied for user 'homestead'@'localhost' (using password: YES)
Whereas, when I am using eloquent functionality in models and trying to populate the database I have to change DB_HOST in .env file to localhost ie DB_HOST=localhost, if not then I get the following error: PDOException in Connector.php line 55: SQLSTATE[HY000] [2002] Connection refused
I have no idea about this. I am all confused. Where am I going wrong??
Leave it as localhost
and try running artisan from within the Homestead virtual machine.
You can access the virtual machine with homestead ssh
or vagrant ssh
. Then move to the document root and run artisan from there.
上一篇: 从本地环境连接到分段数据库