"No such file or directory" or "No such host is known" when running migrations "No such file or directory" or "No such host is known" when running migrations laravel laravel

"No such file or directory" or "No such host is known" when running migrations


If you are using localhost as your DATABASE_HOST in the .env file, change it to 127.0.0.1, then run php artisan config:clear and now try php artisan migrate:install again.


Here's what I recommend for .env file:

DB_CONNECTION=mysqlDB_HOST=localhostDB_PORT=3306

Then in Database.php add folder location:

'unix_socket' => env('DB_SOCKET', '/Applications/MAMP/tmp/mysql/mysql.sock'),

Finally, try:

php artisan config:clearphp artisan migrate:install


If you are using MAMP Pro (not always necessary for the free version of MAMP) then the best thing to do is add this to your .env file:

DB_SOCKET=/Applications/MAMP/tmp/mysql/mysql.sock

This assumes your MAMP installation is at /Applications/MAMP of course (the default).

Credit: A comment in this question by @Uncoke