PDOException SQLSTATE[HY000] [2002] No such file or directory

后端 未结 30 3028
南方客
南方客 2020-11-22 03:23

I believe that I\'ve successfully deployed my (very basic) site to fortrabbit, but as soon as I connect to SSH to run some commands (such as php artisan migrate

30条回答
  •  不知归路
    2020-11-22 03:49

    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"

    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. https://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 https://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.

提交回复
热议问题