Homebrew PHP and MAMP MySQL socket fun

Joe • April 20, 2015

laravel linux

While setting up a new project in MAMP for my day job I ran into an odd problem trying to run artisan migrations.

Running this command:

php artisan migrate:refresh -- env=local

Threw this error:

{"error":{"type":"PDOException","message":"SQLSTATE[HY000] [2002] No such file or directory","file":"\/Users\/halo\/PhpstormProjects\/project\/vendor\/laravel\/framework\/src\/Illuminate\/Database\/Connectors\/Connector.php","line":47}}%

A quick google search came up with this which pointed to:

Short answer: Change "host" in the /app/config/database.php file from "localhost" to "127.0.0.1"

Changing that fixed my issue, but what was the actual cause of the issue?

I installed PHP locally using Homebrew, and MAMP is using it's own versions of PHP and since I was running artisan against my Homebrew version of PHP I needed to point

pdo_mysql.default_socket

to the MySQL socket from MAMP.

Adding

pdo_mysql.default_socket=/Applications/MAMP/tmp/mysql/mysql.sock

to

/usr/local/etc/php/5.6/php.ini

resolved my issue.

Hopefully this helps someone else.