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


After setting up my Laravel app and trying to connect via SSH to run some commands (such asphp artisan migrate[cci] or [cci lang="php"php artisan db:seed) I get an error message:

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

I can see that my tables are there, so it might have worked before – but this doesn’t explain why it isn’t working for me now.


It’s not a big deal. This error message indicates that a MySQL connection via socket is tried (but it seems that it isn’t supported).

When it comes to running Laravel commands (eg. artisan), you probably want to use a different environment. Eg: php artisan migrate --env=production (or whatever environment). See here.

In addition try this for Laravel 5: Change “DB_HOST” in the .env file from “localhost” to “”

About the author