* 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
Comment #1
xjmHmm, 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.
Comment #2
moshe weitzman commentedprobably 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
Comment #3
xjmUsing the loopback IP instead of localhost in settings.php worked perfectly, thanks!
Comment #4
nicksanta commentedI 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.sockhowever, there is a great possibility that this isn't a viable long term solution..
Comment #6
LiveWire commentedCan someone please elaborate. This is beyond me where I make the change to reference the MAMP PHP.
Comment #7
zach harkey commentedI 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
Had I set MAMP to use PHP 5.2, the exact command would have been
For folks using older version of MAMP, the exact command is probably just
Don't forget to make it executable.
Comment #8
aangel commentedThanks, Zach. Your solution solved the problem nicely.
Comment #9
s4j4n commentedI'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:
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 upand 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...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.
Comment #10
entrigan commented#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/phpand then runsudo 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)
Comment #11
jghyde commentedMAMP 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):
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/
Comment #12
srjoshThat worked beautifully. Thanks Joe!
Comment #13
antnerves commentedYou 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:
Symlink to the proper binary:
Make sure you can execute it:
Comment #14
puya commentedThanks 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
Comment #15
puya commentedOops 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:
thanks
Comment #16
jghyde commentedpuya:
Copy back the stock php binary:
#13 and #11 are generally mutually exclusive solutions (-;
Comment #17
s4j4n commentedYou 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.originalIf 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.
Comment #18
cglusky commented#13 works like a champ and is safer than trying to override your stock php links
Comment #19
artt commentedHi Guys,
Drush is well documented. I follow this guide from drush's readme.txt:
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.
Comment #20
s4j4n commentedartt,
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 upon a core update, and let us know if that works for you.Comment #21
artt commenteds4j4n,
You're right, command
drush upfailed and I found some interesting things.I found an error report called "MAMP_php_error_log_MAMP.txt" which listed like this:
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:
That meant there's no chance to employee the php.ini used in MAMP PRO.
php -ito 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.
Comment #22
puya commentedthanks for the suggestions.
Comment #23
longtom commented#7 worked for me, after much frustration. Read it carefully, especially the bit about making the php executable.
Comment #24
jh3 commentedThis 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.
Comment #25
jh3 commentedI 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.
Comment #26
jwbuzz commentedThe quick fix in #2 worked for me
Comment #27
nicksanta commented#2 didn't work for me, but #7 did.
Comment #28
joostvdl commentedSolution #13 worked for me on Snow Leopard + MAMP PRO 1.9
Comment #29
edward_or commentedThanks Zach for #7!
Worked great.
Comment #30
stephenplatz commentedThis was extremely helpful, thanks!
Comment #31
puya commented@#13
#13 worked great and it doesn't alter your system's php at all..
I just think the last line should read :
since we are trying to make the symlink executable right?
Comment #32
ccshannon commented#9 fixed the problem for me. Thanks. That was extremely un-fun, getting drush to work on my Mac. Finally!
Comment #33
Technikal commentedthe antnerve method worked for me - thanx
Comment #34
xmacinfo#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/phpComment #35
xtfer commented#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/binSymlink 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/phpMake sure you can execute it (#31):
sudo chmod a+x /Applications/MAMP/bin/php5/bin/phpFor MAMP 1.9, change line 2 to
sudo ln -s /Applications/MAMP/bin/php5.2/bin/php /Applications/MAMP/bin/php5/bin/phpComment #36
lookatyeti commentedI 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:$PATHAll 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.
Comment #37
xmacinfo@xtfer: Thanks for correcting me.
I confirm that all the steps in #35 are working correctly for MAMP 2.0.1.
Cheers!
Comment #38
altrugon commentedNumber #35 works for me but if you upgrade your drush to 4.5 that should solve the problem too.
Comment #39
xmacinfo@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.
Comment #40
sbakshian commented#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/phpThanks, Zach.
Comment #41
batigolixconfirm 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
Comment #42
danny_joris commented#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.
Comment #43
2dareis2do commentedThankyou
Drush now works. Running Lion with MAMP 2
Comment #44
sco_tt commented#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.
Comment #45
shua commentedI 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
Comment #46
alexgreyhead commentedSolution in #7 worked for me too; thanks Zach!
Comment #47
kip stanning commentedgreat! 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!
Comment #48
marthinal commentedBefore 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.
Comment #49
pratik60 commentedThis 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
Comment #50
ryan88 commented#49 worked perfectly for me!
Thanks.
Comment #51
casismary commentedThank you pratik60 !
#49 works for me :)
Comment #52
blackice2999 commentedHi @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.
Comment #53
c13l0 commented@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 =)
Comment #54
dshumaker commentedFor 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:
and made sure that this
pdo_mysql.default_socket = /Applications/MAMP/tmp/mysql/mysql.sockwas 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:
Or adding the extension to the php.ini file like this:
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