Last updated 30 June 2017. Created on 21 June 2012.
Edited by amourow, swatchion, ShaunDychko, attheshow. Log in to edit this page.

The current version of MAMP may require some troubleshooting to get Drush to work correctly. Known issues include:

  • Default use of php5.3.6 instead of php5.2.17 causes errors upon update, most commonly "Cannot redeclare class" errors. To solve, change the version of PHP in the MAMP preferences panel or add a line in your .bash_profile to tell Drush to use the right version of PHP export DRUSH_PHP="/Applications/MAMP/bin/php/php5.2.17/bin/php".
  • Inability to connect to localhost MySQL via socket. Causes errors like "Error: PDO::__construct(): [2002] No such file or directory (trying
    to connect via unix:///var/mysql/mysql.sock)". To solve, from within Terminal run the following commands:

    sudo mkdir /var/mysql
    sudo ln -s /Applications/MAMP/tmp/mysql/mysql.sock /var/mysql/mysql.sock
    Or, if this error appears with MAMP4, consider checking the "Make this version available on the command line" option.

###################################################

Newly Updated @ 2017-06-01 17:39:12

This page might be a little out-dated.

For most people came to this page is because of the error below:

SQLSTATE[HY000] [2002] No such file or directory in drupal_is_denied() ...

This error is a mysql connection error. To get drush works well under newest MAMP PRO 4.0+, please follow the steps.

  1. Open MAMP PRO -> Main Window -> MYSQL -> Enable [Allow network access to MYSQL and only from this MAC]
    By default, MYSQL server port (default is 3306) is not open and listened, this will open the port.
    MySQL Settings
  2. Open MAMP PRO -> Main Window -> PHP -> Enable [Make this version available on the command line]
    This will make php command executable in terminal.
    PHP Settings
  3. Check mysql configrations
      # Open your terminal and run these command
      mysql_config --socket
      # It will show /Applications/MAMP/tmp/mysql/mysql.sock
      
  4. Repair the sock links and follow instructions posted formerly.
      sudo mkdir /var/mysql
      sudo ln -s /Applications/MAMP/tmp/mysql/mysql.sock /var/mysql/mysql.sock
  5. Add A simple line code to sites/default/settings.php line 247 - line 263 where these code are drupal mysql database settings.

    'unix_socket' => '/var/mysql/mysql.sock',

    $databases = array (
      'default' =>
      array (
        'default' =>
        array (
          'database' => 'your-database',
          'username' => 'database-user-name',
          'password' => 'database-user-passwd',
          'host' => 'localhost',
          'port' => '3306',
          'unix_socket' => '/var/mysql/mysql.sock',
          'driver' => 'mysql',
          'prefix' => '',
        ),
      ),
    );

This will make the sock connection works. And now you can use drush free.

Ps. You may need to remove this line when you go to the production stage, cuz the most popular server environment is linux and mysql.socks settings are fine and works perfectly.

AttachmentSize
mamp_4_drush.png71.18 KB
mamp_4_drush_mysql.png437.04 KB

Looking for support? Visit the Drupal.org forums, or join #drupal-support in IRC.

Comments

mori’s picture

I am using MAMP 2.x on OS X 10.6.8 and OS X 10.8.4

I get this response running "brew doctor" (OS X 10.8.4 with MAMP Pro 2.1.4):

Warning: /usr/bin occurs before /usr/local/bin
This means that system-provided programs will be used instead of those
provided by Homebrew. The following tools exist at both paths:

    git
    git-cvsserver
    git-receive-pack
    git-shell
    git-upload-archive
    git-upload-pack

Consider amending your PATH so that /usr/local/bin
occurs before /usr/bin in your PATH.

Warning: Homebrew's sbin was not found in your path.
Consider amending your PATH variable so it contains:
  /usr/local/sbin

Any suggestions what to do and how?
THANKS!

pratik60’s picture

Been working an hour to get this done

scott.whittaker’s picture

I've just switched to MAMP Pro 3, and it's awesome, but there are a few changes that need to be dealt with for drush to use the correct php.ini file.

In this version of MAMP, you edit the php.ini file by selecting File --> Edit Template --> PHP --> PHP {version} php.ini

This template is actually saved to /Library/Application Support/appsolute/MAMP PRO/conf/php.ini rather than /Applications/MAMP/bin/php/php{version}/conf/php.ini - which does still exist.

I already had the path to the version of PHP I wanted to use in my .bashrc file:

export PATH=/Applications/MAMP/bin/php/php5.5.10/bin:$PATH

and created an alias there to execute PHP with the correct ini file from the command line:

alias php='php -c "/Library/Application Support/appsolute/MAMP PRO/conf/php.ini"'

which runs perfectly when executing PHP from the command line.

Unfortunately drush does not respect this and insists on using the php.ini file from the same location as the php binary.

There does not seem to be any configuration setting that will tell drush which php.ini file to use, but eventually I discovered that a symlink from the php.ini file into ~/.drushrc does work:

ln -s "/Library/Application Support/appsolute/MAMP PRO/conf/php.ini" ~/.drush/

If anyone has a better method I'd love to hear it.

asauterChicago’s picture

ln -s "/Library/Application Support/appsolute/MAMP PRO/conf/php.ini" ~/.drush/

+1 for this. To respond to the last post on this page, the Drush documentation is actually outdated. Adding the symlink was the only thing that worked for me on Yosemite and MAMP 3.2.1. Otherwise it was still using the wrong PHP.ini file.

JMGordon613’s picture

Thanks a bunch! Drush seems to work again with MAMP 3.0.5 and OS X 10.11 Capitan.

+1

bryanbraun’s picture

I found these suggestions out of date. I'd say the best place to look for the most up-to-date instructions regarding Drush and MAMP is the Drush readme on Github. It contains a section for MAMP-specific setups.

: Bryan

d1v9d’s picture

This resolved my problem!!

knalstaaf’s picture

This error occured after updating MAMP. It was solved by using the following commands in Terminal:

sudo mkdir /var/mysql
sudo ln -s /Applications/MAMP/tmp/mysql/mysql.sock /var/mysql/mysql.sock

(Source)

Rick Hood’s picture

I had to uninstall and reinstall MAMP PRO 4.1.1 and this fix worked for me to get Drush running again also:

sudo mkdir /var/mysql
sudo ln -s /Applications/MAMP/tmp/mysql/mysql.sock /var/mysql/mysql.sock
MoCart’s picture

Thanks all for the help. To get Drush working with Drupal on MAMP (MacOS Sierra) I did the following as suggested here and elsewhere:

1) For our Drupal 7.56 site only - Added the socket line above to settings.php:
'unix_socket' => '/Applications/MAMP/tmp/mysql/mysql.sock',

2) For the Drupal 7.56 and 8.3.4 sites - Added to ~./bash_profile:
export PATH=/Applications/MAMP/bin/php/php5.6.30/bin:$PATH

export PATH=/Applications/MAMP/Library/bin:$PATH


Also added the socket symlink: /var/mysql/mysql.sock -> /Applications/MAMP/tmp/mysql/mysql