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

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


I fixed this issue by setting environment variables in .env file:

DB_CONNECTION=mysql 
DB_HOST=mysql 
DB_PORT=3306 

Actually I just changed from DB_HOST=127.0.0.1 to DB_HOST=mysql.


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=mysql
DB_HOST=localhost
DB_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:clear
php artisan migrate:install