Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialWilztan Andrew
Python Web Development Techdegree Student 4,979 Pointspdoexecption sqlstate[hy000]
[PDOException]
SQLSTATE[HY000] [2002] No such file or directory
anyone know how to fix this?
1 Answer
Matthew Bilz
15,829 PointsHi there - this isn't my answer, but I searched for you and found this - hopefully it helps out!
Laravel 4: Change "host" in the app/config/database.php file from "localhost" to "127.0.0.1"
Laravel 5: Change "DB_HOST" in the .env file from "localhost" to "127.0.0.1"
Laravel w/ Homestead: Use the directions above for the Laravel version you are using BUT change "localhost" to the IP address specified in Homestead.yaml. The default is "192.168.10.10" instead of "127.0.0.1" I had the exact same problem. None of the above solutions worked for me. I solved the problem by changing the "host" in the /app/config/database.php file from "localhost" to "127.0.0.1".
Not sure why "localhost" doesn't work by default but I found this answer in a similar question solved in a symfony2 post. http://stackoverflow.com/a/9251924/1231563
Update: Some people have asked as to why this fix works so I have done a little bit of research into the topic. It seems as though they use different connection types as explained in this post http://stackoverflow.com/a/9715164/1231563
The issue that arose here is that "localhost" uses a UNIX socket and can not find the database in the standard directory. However "127.0.0.1" uses TCP (Transmission Control Protocol), which essentially means it runs through the "local internet" on your computer being much more reliable than the UNIX socket in this case.
Wilztan Andrew
Python Web Development Techdegree Student 4,979 PointsWilztan Andrew
Python Web Development Techdegree Student 4,979 Pointsbut if i use 127.0.0.1 it said connection refuse