Digital Media Insights for Business Owners

PDO::__construct(): [2002] No such file or directory – Drush Problem

So let’s say that you decided to install drush in your Mac OS and also you were running MAMP at the time and everything was working great a while ago. But lets say that you decided to upgrade Drush. And you simply grabbed the latest version of Drush from the repository in Drupal.org and everything worked great.

Now, for any crazy reason, let’s say that you decided to install a testing environment of Drupal 7 just for the kicks. And when you do just that you would probably find out that you can’t install Drupal 7 without having enough lift power on your php. It has to be PHP 5.2 at least. That would mean that you have MAMP 1.6 installed in your MAC and therefore you need to upgrade that as well. The process of upgrading the MAMP should be pretty straightforward.

1. Backup your entire MAMP directory in your Applications folder. What I did was to rename it MAMP_bkp and that’s that.

2. I downloaded the new MAMP tarball and then extracted and installed in my Applications folder.

3. I then copied the databases from my backup to my new MAMP folder and that’s it.

4. In case you changed the location of your root directory, then you need to change this also in your MAMP preferences. Where? Go to MAMP > Preferences > APACHE> Document Root  and change it to your old localhost.

Ok so far so good. Now the problem would be if you wanted to simply go back and use Drush. The reason is that now drush is going to give you a nasty error that says something along the lines of:

PDO::__construct(): [2002] No such file or directory (trying to connect via unix:///var/mysql/mysql.sock) [warning]
in drush_valid_db_credentials() (line 952 of
/Users/youruser/Applications/drush/includes/environment.inc).

So what do you do to fix it and go back to having fun?

Solution

The first solution would be to troubleshoot the problem for hours, then go online and try to find an answer and then try to implement all of the ones people talk about and find that some work.

Or you can just type the following:
First, determine where is your php running from in your MAMP. You may do so by creating a simple php file in your root directory and inside the php file type the following:


Now, visit the page and it should show you all your php configurations for your web server. Search for the path.

Now with the path of your php in hand, simply fire up Terminal and type the following command (updated thanks to Phil), make sure that you replace the /Applications/MAMP/bin/php5.3/bin/php part with your own path to php:

AC:d7 youruser$ sudo ln -f /Applications/MAMP/bin/php5.3/bin/php /usr/bin/php

A nice little link.

Now go to a nice restaurant and enjoy a nice meal for 2 hours and then come back to work. You deserve it.

Say: "Hola" to your new clients.

Follow us on Social Media for more Tips & Tricks.

Other Posts You May Enjoy