Hay & Kilner Website Refresh
Hay & Kilner, a Facelift to an Existing CMS Driven Website
2 Comments
Walk To The World Cup - Campaign for Be Air Aware
Walk to the World Cup, a bespoke WordPress plugin
0 Comments
Service Network
Service Network, CMS based events driven website
0 Comments
Numark Pharmacists
Numark Pharmacists, CMS based website and membership based extranet
0 Comments

PHP and PDO on the command line with MAMP

I’ve been working with a couple of command line tasks over the last couple of days using PDO MySQL connections and ran across a problem where PHP on the command line could not connect to MySQL’s default socket. It’s a busy discussion on Google and there seem to be a lot of garbled listings when you google this so here’s my 2 quid.

The reason for my DB connection issue was the version of PHP that was being called was not MAMP’s binary, but the version shipped with OSX. MAMP’s default MySQL socket is not in the usual /var location and in addition to these, when I tried manually running scripts via MAMP’s version(s) I did not have permission to execute them. The result of all this being a whole load of PDO errors and not a lot of progress… So the job would be to make my CLI use the required binary and make sure I can execute it.

To do this you need to open a terminal session and:

1. switch to your home directory if you’re not already there:

$cd

2. add the path to your MAMP install and PHP binary (I’m using 5.3 but you can change this if you like) to a profile file which will be loaded automatically when you log in:

$echo 'PATH=/Applications/MAMP/Library/bin/:/Applications/MAMP/
bin/php5.3/bin/:$PATH' >> .profile

NOTE: you could just add the path line to your .profile using a text editor if you prefer.

3. load your new profile:

$. .profile

4. lastly, make sure you can execute the php binary. You’ll need to enter your admin password here:

$sudo chmod +x /Applications/MAMP/bin/php5.3/bin/php

And that’s it. You should now be able to running the same php config as you are with MAMP and PDO/Mysql sockets etc should be up and running fine.

Post a Comment

Your email is never shared. Required fields are marked *