search

Home  >  Q&A  >  body text

Title rewritten as: PDOException SQLSTATE error encountered, file or directory not found

I believe I have successfully deployed my (very basic) site to fortrabbit, but once I connect to SSH to run some commands (such as php artisan migrate or php artisan db :seed), I get an error message:

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

At some point, the migration must have worked because my tables are there - but that doesn't explain why it's not working for me now.

P粉183077097P粉183077097421 days ago634

reply all(2)I'll reply

  • P粉788765679

    P粉7887656792023-10-11 12:04:03

    One of the simplest causes of this error is that the MySQL server is not running. So check first. If it has started, continue with the other suggestions:

    I encountered 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 problem solved in a symfony2 post. https://stackoverflow.com/a/9251924

    renew: Some people asked why this fix works, so I did some research on the topic. As mentioned in this post, they seem to use different connection types https://stackoverflow.com/a/9715164

    The problem here is that "localhost" uses a UNIX socket and cannot find the database in the standard directory. However, "127.0.0.1" uses TCP (Transmission Control Protocol), which essentially means it runs over the "local internet" on your computer and is much more reliable than a UNIX socket in this case.

    reply
    0
  • P粉356361722

    P粉3563617222023-10-11 10:29:28

    The error message indicates that a MySQL connection was attempted over a socket (not supported).

    In the context of Laravel (Artisan) you may want to use a different/correct environment. For example: php artisan migrate --env=product (or any environment). See here.

    reply
    0
  • Cancelreply