phpmacosyiiterminalmamp

Using terminal, how do I make OS X use MAMPs version of PHP


I'm currently learning the Yii framework, and one of the tutorials I was running through yesterday required me to test the database connection of a project.

The details aren't too important here, but basically when I run shell, and type in the command it throws up an error as follows:

server:trackstar charlieryan$ protected/yiic shell

Yii Interactive Tool v1.1 (based on Yii v1.1.13) Please type 'help' for help. Type 'exit' to quit.

echo Yii::app()->db->connectionString; PHP Warning: PDO::__construct(): [2002] No such file or directory (trying to connect via unix:///var/mysql/mysql.sock) in /Applications/MAMP/htdocs/trackstar/yii/framework/db/CDbConnection.php on line 423 exception 'CDbException' with message 'CDbConnection failed to open the DB connection: SQLSTATE[HY000] [2002] No such file or directory' in /Applications/MAMP/htdocs/trackstar/yii/framework/db/CDbConnection.php:381 Stack trace:

As far as I understand this is because Mac OS X's own version of PHP is being used which does not have support for a MySQL PDO Driver, but MAMP's own version does.

When I do the "which php" command, it returns "/usr/bin/php", which is the incorrect version. How do I change this to default to the MAMP version?


Solution

  • When I do the "which php" command, it returns "/usr/bin/php", which is the incorrect version. How do I change this to default to the MAMP version?

    You need to add the MAMP version to your path or invoke it with the full path. I'm not sure where MAMP's php binary lives but let's say its in /Applications/MAMP/bin. So in that case you'll need to add that path to your .profile:

    vi ~/.profile
    # if there is a PATH=... line add the mamp path in front of all the others
    PATH=/Applications/MAMP/bin:/existing/paths/if/any:$PATH
    

    then either close terminal or run the command:

    source ~/.profile

    This will reload your profile. Now if you do which php it should find the MAMP version first. Again, I don't know that that is the correct path for the MAMP bin dir, so you need to verify that and use the correct one.