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.
-
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.
-
Open MAMP PRO -> Main Window -> PHP -> Enable [Make this version available on the command line]
This will make php command executable in terminal.
-
Check mysql configrations
# Open your terminal and run these command mysql_config --socket # It will show /Applications/MAMP/tmp/mysql/mysql.sock
-
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
-
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.
Attachment | Size |
---|---|
mamp_4_drush.png | 71.18 KB |
mamp_4_drush_mysql.png | 437.04 KB |
Comments
For which versions of OS X & MAMP is this necessary
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):
Any suggestions what to do and how?
THANKS!
Thanks for this
Been working an hour to get this done
MAMP Pro 3
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.
ln -s "/Library/Application
+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.
It worked
Thanks a bunch! Drush seems to work again with MAMP 3.0.5 and OS X 10.11 Capitan.
+1
See the Drush readme
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
Thank you!
This resolved my problem!!
MAMP update
This error occured after updating MAMP. It was solved by using the following commands in Terminal:
(Source)
That last suggestion worked for me also
I had to uninstall and reinstall MAMP PRO 4.1.1 and this fix worked for me to get Drush running again also:
These fixes worked for me
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
Possible Fix on Drupal 8/Drush 9 with MAMP 4.2.1 on OSX 10.11.6
After searching for hours and trying the Drush documentation instructions over and over, I found this thread on d.O. I was excited until I read that it pertained to MAMP PRO. Though, after working through the steps and following some of what others have said about the path for unix_socket in settings.php (or settings.local.php), I was able to successfully run Drush. I'm running Drupal 8.4.1 and Drush 9.0.0-beta9 on MAMP 4.2.1 on OSX 10.11.6.
Just to reiterate, I followed what I could in the instructions above that pertained to the free MAMP (not MAMP PRO), steps 3, 4 and 5 being key, and used @MoCart's suggested path of 'unix_socket' => '/Applications/MAMP/tmp/mysql/mysql.sock' in my settings.php file (would also work with settings.local.php) after line 794.
'drush status' and 'drush cr' work. I'll follow up if I have any future issues.
Thanks to those that put in the energy and thought to post this. I can now get back to actually developing!
The solution from the last comment worked for me
Setting
in the databases array inside the settings.php, was what helped me out. Thank you!
Steps for configuring MAMP and Drush
Steps for configuring MAMP and Drush
This sequence on macOS 10.13.1 Higher Sierra worked perfectly with MAMP PRO 4.x
1. Edit ~/.zshrc or ~/.bashrc add following line of-course you can change PHP Version you like
export PATH=/Applications/MAMP/bin/php/php7.0.22/bin:/Applications/MAMP/Library/bin/mysql:$PATH
2. Run following command
ln -s "/Library/Application Support/appsolute/MAMP PRO/conf/php.ini" ~/.drush/
3. Run following
4. Run following command
sudo ln -s /Applications/MAMP/Library/bin/mysql /usr/local/bin/mysql
5. If needed add this line to settings.php where you connecting to mysql
'unix_socket' => '/Applications/MAMP/tmp/mysql/mysql.sock',
mysqldump
Thanks a lot. It only took step 3. and 4. on a freshly installed mac OS High Sierra. And step 4. I'd additionally add:
ln -sf /Applications/MAMP/library/bin/mysqldump /usr/local/bin/mysqldump
Works great
Works great + nice addition. Thanks
MAMP 6, macOS 11
Yes, only step 3 and 4 needed on MAMP 6, macOS 11. Thank you all for these tips!
Thank you amjad1233, it works
Thank you amjad1233, it works perfectly !
http://kiliweb.fr/
If you have Acquia installed..
Drush worked great with my Acquia Desktop, but I did prefer all my local projects under MAMP, so first I did remove the drush installation of Acquia and then I changed the export path to the current drush installation. After which I did get the above errors that you mentioned, I did download mysql and mysql-client (brew install mysql and brew install mysql-client), after which I followed all your instructions and voila! it worked.
Thank you!
MAMP PRO 5.3
sudo ln -s /Applications/MAMP/tmp/mysql/mysql.sock /var/mysql/mysql.sock
allows to uselocalhost
on both drush and UI.