Getting this error? [PDOException] SQLSTATE[HY000] [2002] No such file or directory

Getting this error? [PDOException] SQLSTATE[HY000] [2002] No such file or directory

PHP Artisan Migrate – Laravel 5 – Mac – MAMP


Update 2015-07-29 : As Alejandro pointed out in the comments below, FIRST try changing your “localhost” to and see if it works. If not, read on…


I know this is a rather specific issue, but I still hope it helps somebody out there. When using Laravel 5 (or even Laravel 4, for that matter) on a Mac using MAMP you might come across the following error when trying to use PHP Artisan to run migrations for the first time:

It’s a super easy fix, however, it’s kind of buried in the documentation. Open your database.php config file, and add the following line to the mysql array:

Your final array should look something like this:


XAMPP user? … I’ve been told (but haven’t tested this) you could instead use this:

… in the same way as above.


  1. You just saved me a lot of work with this!

    Thank you very much!

    • Hi Denis! Glad it helped!

      • hello, where i can find this file in filezilla?where is located

  2. Way great work man, keep it up

    • Thank you Prakhar!! 🙂

  3. For me, the solution was put instead of “localhost”. With a Mac and no Mamp or Xamp installed. Wierd.

    • HI Alejandro!

      I have just verified that using just the IP will work in some set ups, and not in others. Thank you for the note!! I’ve updated the article and I appreciate your input!!

      Cheers! 🙂

  4. Thx for solution

    • Hi Yegor!

      You’re welcome! 🙂

  5. Thanks a lot

    • You’re welcome a lot!

  6. found this post after 4 hours 🙂 thanks

    • 🙂 Glad it helped! 🙂

  7. Thank you for this! Being new to PHP and Laravel, I was racking my brain over this.

    • Hi Denham… super! Welcome to the PHP/Laravel club, we’re glad you’re here! 🙂

  8. Thank you so much, it’s working fine for me..!!

  9. Im having the same error when just running php artisan serve. When i goto localhost:8888, i get this error. Ive added the suggested line but no help. 🙁

    • You’re welcome!

  10. Thank you very much,John . I applied your suggestion on the array connection and worked fine.

  11. Hi John, i had the same issue after update MAMP from 3.5 -> 3.5.2

    Thank you so much for sharing this solution!

Submit a Comment

Your email address will not be published. Required fields are marked *