2

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?

1 Answer 1

0

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!

Sign up to request clarification or add additional context in comments.

1 Comment

I am also using WAMP, and when I connect to my vm and type php artisan or php artisan tinker etc. (inside my project, vagrant/Code/Laravel) I get an error: The program 'php' is currently not installed. You can install it by typing: sudo apt-get install php5-cli

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.