Getting Composer Working in OSX with MAMP

I just had a bit of a run-around trying to get Composer working in my local MAMP environment, so I thought I’d share a few of the extra steps I had to go through.

First off, you need to get your command-line interpreter (CLI) to recognize MAMP’s version of PHP, not the built-in. So open a Terminal window, type “sudo nano ./bash_profile” and there should be a line that looks something like this:

export PATH=/opt/local/bin:/opt/local/sbin:$PATH

You need to edit that to add the MAMP version of PHP before /opt/local/bin, like so (this is for PHP 5.3.14):

export PATH=/Applications/MAMP/bin/php/php5.3.14/bin:/opt/local/bin:/opt/local/sbin:$PATH

You can confirm which PHP install is running on the CLI by executing “which php” (you may need to open a new terminal window). Then when installing Composer you need to make sure to set detect_unicode to Off. You can do that and install Composer all at once like this:

$ curl -sS | php -d detect_unicode=Off

That will download Composer to your current directory. After that, we’ll want to move it to a more readily accessible location and set up an alias for it so that you can just use “composer <foo>” from the CLI:

$ sudo mv composer.phar /usr/bin/
$ nano ~/.bash_profile

Then add the following line to your .bash_profile file:

$ alias composer="php /usr/bin/composer.phar"

After that, you should be all set!

Before figuring this out, I was trying to install Laravel, which involved installing Composer, and running into problems like “openssl extension is missing” and “The detect_unicode setting must be disabled.” So hopefully if you’re running into those problems in an OSX/MAMP environment, this will help you.

Category(s): Tools
Tags: , , ,

Leave a Reply

Your email address will not be published. Required fields are marked *