* Mac OS 10.6
* Apache and PHP recompiled from source to use PHP 5.2.10
* MySQL and so on installed via macports as per http://drewish.com/node/110

[kepler:/Library/WebServer/Documents/d6 | 13:00:23]$ drush --debug status
Found command: status (commandfile=core) [0.03 sec, 3.46 MB] [bootstrap]
Drush bootstrap phase : _drush_bootstrap_drupal_root() [0.03 sec, 3.47 MB] [bootstrap]
Initialized Drupal 6.15 root directory at /Library/WebServer/Documents/d6 [0.03 sec, 4.25 MB] [notice]
Drush bootstrap phase : _drush_bootstrap_drupal_site() [0.03 sec, 4.26 MB]  [bootstrap]
Initialized Drupal site default at sites/default [0.03 sec, 4.26 MB] [notice]
Drush bootstrap phase : _drush_bootstrap_drupal_configuration() [0.03 sec, 4.26 MB] [bootstrap]
PDO::__construct(): [2002] No such file or directory (trying to connect via unix:///tmp/mysql.sock) environment.inc:939 [0.03 sec, 4.27 MB] [warning]
SQLSTATE[HY000] [2002] No such file or directory [0.03 sec, 4.29 MB][warning]
 Drupal Root            :  /Library/WebServer/Documents/d6 
 Drupal Version         :  6.15                            
 Site Path              :  sites/default                   
 Site URI               :  http://default                  
 Database Driver        :  mysqli                          
 Database Hostname      :  localhost                       
 Database Username      :  drupal                          
 Database Name          :  drupal                          
 Database Password      :  xxxxxxxxxxx
 Default theme          :  garland                         
 Administration theme   :  garland                         
 PHP configuration      :                                  
 Drush Version          :  All-versions-3.0-beta1          
 Drush configuration    :                                  
Command dispatch complete [0.04 sec, 4.26 MB] [notice]
 Timer  Cum (sec)  Count  Avg (msec) 
 page   0.002      1      2.24       
Peak memory usage was 4.34 MB [0.04 sec, 4.26 MB] [memory]

My site works fine (no problems with database connectivity); it's just drush commands that fail with this PDO::__construct() error.

I don't think this is a bug in Drush; it seems like it's probably a missing configuration somewhere, but I am not sure what. Any suggestions?

Comments

xjm’s picture

Version: All-Versions-2.1 » All-versions-3.0-beta1

Hmm, I thought I had downloaded the 2.x version, but apparently not. In either case, I get the same issue with the 2.x release.

moshe weitzman’s picture

Status: Active » Fixed

probably your CLI PHP uses a different php.ini than the web site does. you have to customize it also.

one quick fix may be to use 127.0.0.1 instead of localhost in your db_url

xjm’s picture

Using the loopback IP instead of localhost in settings.php worked perfectly, thanks!

nicksanta’s picture

I tried changing 'localhost' in my $db_url string to 127.0.0.1, but that ended up throwing a bunch more errors.

My 'solution' was to create a symbolic link to the actual mysql.sock file, like this:
ln -s /Applications/MAMP/tmp/mysql/mysql.sock /tmp/mysql.sock
however, there is a great possibility that this isn't a viable long term solution..

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

LiveWire’s picture

Can someone please elaborate. This is beyond me where I make the change to reference the MAMP PHP.

Zach Harkey’s picture

I started having this problem shortly after I upgraded to MAMP & MAMP PRO 1.9 which allows you run PHP 5.2 OR PHP 5.3. For me the problem only started happening after I changed my version of PHP, (Even then it didn't start happening right away.)

The solution was indeed to reference the MAMP PHP.

For me, because I had MAMP set to use PHP 5.3, the exact command was

sudo ln -f /Applications/MAMP/bin/php5.3/bin/php /usr/bin/php

Had I set MAMP to use PHP 5.2, the exact command would have been

sudo ln -f /Applications/MAMP/bin/php5.2/bin/php /usr/bin/php

For folks using older version of MAMP, the exact command is probably just

sudo ln -f /Applications/MAMP/bin/php5/bin/php /usr/bin/php

Don't forget to make it executable.

sudo chmod +x /usr/bin/php
aangel’s picture

Thanks, Zach. Your solution solved the problem nicely.

s4j4n’s picture

I'm using OS X 10.6 and MAMP Pro, had similar problems when using drush and changed my .bash_profile as follows which seemed to fix the problem:

alias drush='/Applications/MAMP/bin/php5.2/bin/php /opt/drush/drush.php'
export COLUMNS

And drush worked fine for me for a while.

Today I tried to update my site and things didn't go so well. I ran drush up and drush was able to update the modules without printing an error. When it came to the core, it seems it updated core but when it had to update the database something went wrong...

 **snip**

Note: Updating core can potentially break your site. It is NOT recommended to update production sites without prior testing.
Do you really want to continue? (y/n): y
Project drupal was updated successfully. Installed version is now 6.16.
Backups were saved into the directory                                [ok]
/Users/lclusr/wwwroot/example/backup/modules/20100503172700/drupal.
You have pending database updates. Please run `drush updatedb` or    [warning]
visit update.php in your browser.
The external command could not be executed due to an application     [error]
error.
SQLSTATE[HY000] [2002] No such file or directory                     [warning]
Drush was not able to start (bootstrap) the Drupal database.         [error]
Hint: This error often occurs when Drush is trying to bootstrap a
site that has not been installed or does not have a configured
database.

Drush was attempting to connect to : 
  Drupal version    : 6.16
  Site URI          : http://default
  Database driver   : mysqli
  Database hostname : localhost
  Database username : example
  Database name     : example
  Default theme     : garland
  Administration theme: garland
  PHP configuration : 
  Drush version     : All-versions-3.0
  Drush configuration: 
  Drupal root       : /Users/lclusr/wwwroot/example
  Site path         : sites/default
  Modules path      : sites/all/modules
  Themes path       : sites/all/themes
  File directory path: sites/default/files
  %paths            : Array

You can select another site with a working database setup by
specifying the URI to use with the --uri parameter on the command
line or $options['uri'] in your drushrc.php file.

Drush command could not be completed.                                [error]
Output from failed command :                                         [error]
 
An error occurred at function : drush_pm_post_pm_update              [error]

After this I check my site and it is working, module and core seem to be updated, only I am presented with a message that I need to run updates. I update date the database from within drupal without any issues.

Why aren't the .bash_profile changes I made shown above sufficient?

fyi I tried using 127.0.0.1 but that also broke my site, so I had to change it back to localhost.

I was trying to avoid using the link approach but I guess I'll have to give it a try.

entrigan’s picture

#7 worked excellent for me with one modification (I do not really know what I am doing): I had to first delete the existing file with sudo rm /usr/bin/php and then run sudo ln -f /Applications/MAMP/bin/php5.2/bin/php /usr/bin/php. Thanks Zach!

Also dont forget to make your mamp php executable.

Lastly the editing the .bash_profile method to reference the php did not work for me (do not know why)

jghyde’s picture

MAMP Pro 1.9
Mac OS X Snow Leopard

Thanks everyone for the info here. I'd like to add one more step, because if you ever delete MAMP, or uninstall it, you are going to lose the stock MAC OS X php executable.

On the Terminal in MAC OS (Snow Leopard), assuming you are configured to be using php 5.2 in MAMP (chg 5.2 for 5.3 if you want to use php 5.3):

  1. sudo cp /usr/bin/php /usr/bin/php.stock
  2. sudo ln -f /Applications/MAMP/bin/php5.2/bin/php /usr/bin/php
  3. sudo chmod 755 /usr/bin/php

In your site's settings.php, set the database line to use "localhost', eg:

[tcl] is the name of my database:

$db_url = 'mysql://root:passwd@localhost/tcl';

(on line 92 or so)

This works!

Joe
http://www.hydeinteractive.com/

srjosh’s picture

That worked beautifully. Thanks Joe!

antnerves’s picture

You don't need to unlink your system php binary to fix this.

The MAMP php directory structure changed, and the drush shell script doesn't reflect this (yet). Drush looks for a MAMP php in /Applications/MAMP/bin/php5/bin, so I just created a symlink to the new location of the MAMP php binary. I'm using 5.2, so replace with 5.3 if necessary.

Create the missing directory:

sudo mkdir -p /Applications/MAMP/bin/php5/bin

Symlink to the proper binary:

sudo ln -s /Applications/MAMP/bin/php5.2/bin/php /Applications/MAMP/bin/php5/bin/php

Make sure you can execute it:

sudo chmod a+x /Applications/MAMP/bin/php5.2/bin/php
puya’s picture

Thanks for all the info, could somebody please tell me what do I need to do to revert back to the original MAC OS php when I uninstall MAMP? I seem to have lost it using the "sudo ln -f /Applications/MAMP/bin/php5.2/bin/php /usr/bin/php" command?

Thanks

puya’s picture

Oops I totally broke my drush command by using #11 followed by #13 ! Would really appreciate some help reverting back to the original state.
now I am getting:

drush php-eval
WD php: Missing argument 1 for drush_core_php_eval() in [error]
/Network/Servers/hal.myg5.com/Users/pooya/Sites/drush/commands/core/core.drush.inc on line 602.
Missing argument 1 for drush_core_php_eval() in [warning]
/Network/Servers/hal.myg5.com/Users/pooya/Sites/drush/commands/core/core.drush.inc on line 602.

thanks

jghyde’s picture

puya:

Copy back the stock php binary:

sudo rm /usr/bin/php  // <-- assuming you have ls -la /usr/bin/php.stock | grep stock
sudo cp /usr/bin/php.stock /usr/bin/php

#13 and #11 are generally mutually exclusive solutions (-;

s4j4n’s picture

You should definitely backup your /usr/bin/php before you follow #11 or #13 above, i.e. something like...

cp /usr/bin/php /usr/bin/php.original

If you've lost your original php, perhaps at a future mac OS update you might get it back? In the interim, why not just reinstall MAMP and use #11 or #13 above? MAMP doesn't need to be running to use the php provided.

cglusky’s picture

#13 works like a champ and is safer than trying to override your stock php links

artt’s picture

Hi Guys,

Drush is well documented. I follow this guide from drush's readme.txt:

NOTE FOR ADVANCED USERS
- If you want to run drush with a specific version of php, rather than the
one found by the drush command, you can instead create an alias that
executes the drush.php file directly:
$ alias drush='/path/to/php/php5 /path/to/drush/drush.php'
If you do this, to allow Drush to detect the number of available columns,
you need to add the line 'export COLUMNS' to the .profile file in your
home folder.

I use MAMP PRO 1.9, and I set up this in my .bash_profile on my macbook 10.6:

# According to drush readme.txt, fix the right php version. In my case, I use MAMP PRO php 5.2 version.
alias drush='/Applications/MAMP/bin/php5.2/bin/php /usr/local/drush/drush.php'

export COLUMNS

Then everything goes fine. No need to modify /usr/bin/php.

s4j4n’s picture

artt,

that only partially works - as described in #9 above. Some simple drush commands may work for you in that setup, however more complex procedures like updating core fail (at least for me... I'm using 10.6 and 1.9 Pro as well).

Try drush up on a core update, and let us know if that works for you.

artt’s picture

s4j4n,

You're right, command drush up failed and I found some interesting things.

  1. Using drush alias would get this error:
    ...snipped...
    Project drupal was updated successfully. Installed version is now 6.17.
    Backups were saved into the directory                                [ok]
    /Users/art/sites/peco222/backup/modules/20100731001758/drupal.
    The command could not be executed successfully (returned: env: php:  [error]
    No such file or directory
    , code: <em>127</em>)
    An error occurred at function : drush_pm_post_pm_update              [error]
    

    I found an error report called "MAMP_php_error_log_MAMP.txt" which listed like this:

    [31-Jul-2010 00:22:15] PHP Warning:  PHP Startup: Unable to load dynamic library 'MAMP_extension_dir_MAMP/imap.so' - (null) in Unknown on line 0
    
  2. So I made a linked php in /usr/bin, then I met another issue:
    ...snipped...
    Fatal error: Allowed memory size of 33554432 bytes exhausted (tried
    to allocate 901 bytes) in
    /Users/art/Sites/peco222/includes/database.mysql-common.inc on line 41
    
    An error occurred at function : drush_pm_post_pm_update              [error]
    

    Interestingly, it didn't use the php.ini I set in MAMP PRO 1.9. I checked the manual of MAMP PRO and found that:

    The configuration files are generated from the settings made within MAMP PRO. MAMP PRO uses templates for this purpose where further configuration options are included. You can edit these templates from the menu item File > Edit template. Here, you have access to options which are not accessible from the MAMP PRO user interface.

    That meant there's no chance to employee the php.ini used in MAMP PRO.

  3. After using php -i to check what php.ini it used, I found it's /Applications/MAMP/conf/php5.2. So I copied php.ini template in MAMP PRO to /Applications/MAMP/conf/php5.2/php.ini.
    Then, everything worked.

Thanks for your information.

puya’s picture

thanks for the suggestions.

longtom’s picture

#7 worked for me, after much frustration. Read it carefully, especially the bit about making the php executable.

jh3’s picture

Component: Installation » PM (dl, en, up ...)

This recently just began happening to me for what seems like absolutely no reason.

I've been happily using drush to download modules and themes on my local machine for drupal sites in git repositories. Yesterday I went to download a module and receieved the following:

PDO::__construct(): [2002] No such file or directory (trying to connect via unix:///var/mysql/mysql.sock) environment.inc:952
SQLSTATE[HY000] [2002] No such file or directory

No idea why this is happening and it is very, very annoying. I thought it had to do with the particular site I was working in, but it is every site I have on my computer. In one site/repo on my machine when I run a drush command it cats out an error page instead of giving me any actual drush warnings. Again, no idea why this would be happening.

I don't have the sites' databases on my local machine and I'm not using MAMP; they reside on a development server. Also, my settings.php file has the information for the remote server.

This really just started yesterday and before then everything was working flawlessly. Any ideas before I begin ripping my hair out?

Edit: I'm using the version of php that came with osx 10.6, which is php 5.3, but the server my site is on is using php 5.2. Again, this was all working fine up until a day or two ago.

jh3’s picture

I think I've solved my problem. Some how the remote server's db information ended up in my local settings.php, which was causing drush to try and connect to a non-existent database. I ended up completely removing settings.php from my repo because it really shouldn't be there anyway.

jwbuzz’s picture

The quick fix in #2 worked for me

nicksanta’s picture

#2 didn't work for me, but #7 did.

joostvdl’s picture

Solution #13 worked for me on Snow Leopard + MAMP PRO 1.9

edward_or’s picture

Thanks Zach for #7!
Worked great.

stephenplatz’s picture

This was extremely helpful, thanks!

puya’s picture

@#13

#13 worked great and it doesn't alter your system's php at all..

I just think the last line should read :

chmod a+x /Applications/MAMP/bin/php5/bin/php

since we are trying to make the symlink executable right?

ccshannon’s picture

#9 fixed the problem for me. Thanks. That was extremely un-fun, getting drush to work on my Mac. Finally!

Technikal’s picture

the antnerve method worked for me - thanx

xmacinfo’s picture

#13 works as well for MAMP 2.0 and Drush.

However, make sure that you are symlinking the proper MAMP 2.0 PHP file:

[Edited to the correct order, but please see #35:]
sudo ln -s /Applications/MAMP/bin/php/php5.2.17/bin/php /Applications/MAMP/bin/php5.2/bin/php

xtfer’s picture

#13 & #34 are on the right track but have minor typos...

The correct sequence for MAMP 2.0 (#13) is:

Create the missing directory:
sudo mkdir -p /Applications/MAMP/bin/php5/bin

Symlink to the proper binary (#34 in reverse order):
sudo ln -s /Applications/MAMP/bin/php/php5.2.17/bin/php /Applications/MAMP/bin/php5/bin/php

Make sure you can execute it (#31):
sudo chmod a+x /Applications/MAMP/bin/php5/bin/php

For MAMP 1.9, change line 2 to
sudo ln -s /Applications/MAMP/bin/php5.2/bin/php /Applications/MAMP/bin/php5/bin/php

lookatyeti’s picture

I was experiencing this same issue with OS X 10.7 and MAMP PRO 2.0

I upgraded to MAMP PRO from MAMP where everything was working just fine. Here are the updates that I made to get all of my sites running and Drush working again:

MAMP PRO Updates:

increase php memory_limit in two places (256M probably overkill for most)
- file -> edit template -> php 5.3.6
- applicaitons/mamp/bin/php/php5.3.6/conf/php.ini **

increase max_allowed_packet (32M probably overkill for most)
- file -> edit template -> MySQL my.conf

Add the following line to .profile / .bashrc / .bash_profile (whichever) then restart terminal
export PATH=/Applications/MAMP/bin/php/php5.3.6/bin:/Applications/MAMP/Library/bin:$PATH

All of this can be adjusted accordingly for php 5.2.17

Best of luck all!

*UPDATE*
Don't forget to restart your servers after the config updates.

xmacinfo’s picture

@xtfer: Thanks for correcting me.

I confirm that all the steps in #35 are working correctly for MAMP 2.0.1.

Cheers!

altrugon’s picture

Number #35 works for me but if you upgrade your drush to 4.5 that should solve the problem too.

xmacinfo’s picture

@altrugon: Upgrading to Drush 4.5 alone did not solve the issue, at least not when moving from MAMP 2.0.1 to 2.0.3. I still had to use #35 life saving tricks.

sbakshian’s picture

#7 Worked for me with MAMP Pro 2.0.3 !! :)

I just modified it to be:
sudo ln -f /Applications/MAMP/bin/php/php5.2.17/bin/php /usr/bin/php

Thanks, Zach.

batigolix’s picture

confirm that the symbolic link as explained above works for mamp 2.0.3 and osx 10.7.1:

sudo ln -f /Applications/MAMP/bin/php/php5.3.6/bin/php /usr/bin/php

Danny_Joris’s picture

#35 solved it for me.

Drush 4.5
MAMP 2.0.5
OS X 10.6.8

Edit:
My MAMP preference actually was set to use php5.3.6 , so just copying #35 made my setup link to the php5.2.17 php.ini file. So I had to recreate the link to php5.3.6.

2dareis2do’s picture

Thankyou
Drush now works. Running Lion with MAMP 2

sco_tt’s picture

#13 modified to 5.2.17 per #40 worked for me. It wasn't working at first, because I had installed the Acquia Dev environment sometime back and never really worked in it, but my dev environments set up via mamp were using that PHP--a closer reading of 'drush status' from the beginning would have save me some time. ;) I just deleted the Acqui devel environment, and the modified instructions from #13 worked great.

shua’s picture

I created a patch for drush here.
Notice that you have to configure the mysql-socket under settings.php as a unix_socket
http://drupal.org/node/1420312

alexharries’s picture

Solution in #7 worked for me too; thanks Zach!

kip stanning’s picture

great! thx ZACH! i am using php 5.2 but the directory-name is php5 (not php5.2 as in your example). when TERMINAL told me that there was no directory like the one specified in my first try i only had to correct the path and all worked perfectly. after a day of desparate work the problem finally was solved! thx again!

marthinal’s picture

Before create a soft link (ln -s) with your php, it's important that you find the correct path using command "which php".Then create the link with your php mamp path and the result of the which command.

pratik60’s picture

This worked for me

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

So much of trial and error

ryan88’s picture

#49 worked perfectly for me!
Thanks.

casismary’s picture

Thank you pratik60 !

#49 works for me :)

Blackice2999’s picture

Hi @all,

i use OS X with MAMP 3.x and i run into the same problem but i dont want to solve it by moving and symlinking system files on OS X. There a two part that be needed to set.

First part. Drush need to known which PHP Version to be executed. This can be solved by multiple ways. I chose the way by setting the path to binaries before other path will be set. (Like: http://docs.drush.org/en/master/configure/#drushrcphp#additional-configu... )

The second part was that PHP need to known how to connect to MySQL this is normaly done by the PHP.INI with:

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

but on newer MAMP Version we get again the "no such file or directory" error... after some debugging i found that the PHP extension "pdo_mysql" uses it own default socket setting... so we need also a configuration line for pdo:

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

hopes this helps someone.

C13L0’s picture

@Blackice2999 Thank you! I just updated mamp pro 3.x and had this issue. I went to Applications ▸ MAMP ▸ bin ▸ php ▸ php5.6.6 ▸ conf ▸ php.ini and added pdo_mysql.default_socket = /Applications/MAMP/tmp/mysql/mysql.sock to php.ini file and restarted the server. Everything works perfect =)

dshumaker’s picture

For what its worth. None of the solutions above worked for me.

I'm running OSX Yosemite, MAMP PRO 3.1, PHP 5.4.38.

I had done this:

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

and made sure that this
pdo_mysql.default_socket = /Applications/MAMP/tmp/mysql/mysql.sock
was added to my /Applications/MAMP/bin/php/php5.4.38/conf/php.ini file.

But none of that helped. I still got a PDO exception for drush. Indicating drush not being able to connect to mysql.

The only thing that worked for me either using a php that was able to connect like this:

alias drush='/Applications/MAMP/bin/php/php5.4.34/bin/php /usr/local/Cellar/drush/HEAD/libexec/drush.php'

Or adding the extension to the php.ini file like this:

extension=pdo_mysql.so

I'm not sure why that pdo_mysql.so line was missing from the php5.4.38/conf/php.ini file. I've submitted a bug report to MAMP.

---Update---
Got it working with the
'host' => '127.0.0.1'
solution mentioned here: http://drupal.stackexchange.com/questions/99446/pdoexception-with-drush