HOST=localhost and 127.0.0.1 PDOException

I'm using Laravel 5 on Windows 10, VB, homestead and I am still new, I've just started learning Laravel.

When I run my project in Chrome using DB_HOST=127.0.0.1 in .env file I get this error message: PDOException in Connector.php line 55: SQLSTATE[HY000] [2002] Connection refused

and when I change DB_HOST to localhost everything is fine except when I am using tinker (php artisan tinker). I get this message: PDOException with message 'SQLSTATE[HY000] [2002] No such file or directory'

Database works with DB_HOST=localhost and tinker DB_HOST=127.0.0.1

So, I can't use both at the same time, everytime I must change DB_HOST in .env file from localhost to 127.0.0.1

What can I do to fix this issue?


If you're using Homestead, your DB_HOST should be set to localhost.

The reason why in such case artisan (migrate) cannot connect to database is because you are not executing the commands inside your virtual machine.

To do it the right way connect to your vm using:

vagrant ssh

and once logged in, continue as you'd normally.

Hope that helps!

链接地址: http://www.djcxy.com/p/33070.html

上一篇: Git克隆的laravel 5.2项目不会迁移

下一篇: HOST = localhost和127.0.0.1 PDOException