Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
How to install Composer globally using MAMP's PHP

##Create an alias to MAMP's PHP installation

To do this, we can simply create an alias for our bash profile. We'll be doing this is nano, though you can do it in vim or a number of other editors as well.

Within the terminal, run:

nano ~/.bash_profile

This will open nano with the contents, at the top in a blank line add the following line:

alias phpmamp='/Applications/MAMP/bin/php/php5.4.10/bin/php'

This will create an alias, phpmamp, so that you can take advantage of the MAMP installation of PHP. Please take note of the PHP version, in this case 5.4.10, as with different versions of MAMP this may be different. Check your installation and see what version you have, and replace the number accordingly (this was written with MAMP version 2.1.2).

With that setup, we are ready to install composer. This is a two step process if we would like this to be installed globally, while you would only need to do the first step if you would like this installed to the local working directory only.

First, run the following command in the terminal:

curl -sS | phpmamp

Note that instead of the standard 'php' at the end, we are using 'phpmamp' so that we correctly use the MAMP installation of PHP.

Next, we want to make this available globally, so we need to move the file to '/usr/local/bin/composer'. To do this, run the following command:

sudo mv composer.phar /usr/local/bin/composer

Terminal will ask you for yor password, after entering it and pressing the 'return' (or enter) key, you'll have a working global installation of composer on your mac that uses MAMP!

You can verify your installation worked by typing the following command:


It'll show you the current version and a list of commands you can use!

Copy link

Hestabit commented Dec 25, 2017

Its awesome thanks a lot.

Users who are getting error -bash: phpmamp: command not found curl: (23) Failed writing body (0 != 16384) need to source .bash_profile. use this command source ~/.bash_profile

Copy link

digeek commented Feb 23, 2018


Copy link

TheBigSteph commented Mar 13, 2018


Copy link

StonehengeCreations commented Jul 14, 2018

Okay, with all the comments I lost track...
On Mac OSX High Sierra /usr/local/bin doesn't exist. I created it: sudo mkdir /usr/local/bin/composer

I rerun Terminal, run the commands, get no errors.
Still composer does not work. "Command not Found".

Please help.

Copy link

scorchio commented Jul 23, 2018

Superb guide, thank you!

@StonehengeCreations - make sure that /usr/local/bin is part of your PATH environment variable. You can set this in your .bash_profile.

Copy link

brokenmachine commented Sep 7, 2018

Many thanks for creating this!

Copy link

ThomRockwell commented Oct 11, 2018

Wonderfully simple! Thanks so much!

Copy link

anabrownee commented Nov 4, 2018

thanks, this worked like a charm!

Copy link

bertrandBourgy commented Jan 12, 2020

When I run the curl command I get a "zsh: command not found: phpmamp" error. Any suggestions?
simply restart the terminal

Copy link

ty1l3r commented Mar 23, 2020

Thank you !

Copy link

francisco83 commented Sep 9, 2020

Muchas Gracias!

Copy link

fiqriachmada commented Jan 24, 2021

Thanks for the guide

Copy link

davidrhoden commented May 17, 2021

still working in 2021, thank you

Copy link

mosaabramadan commented Jun 10, 2021

thanks alot

Copy link

patovd commented May 18, 2022

In Mac OS, if you get this error

zsh: command not found: phpmamp
curl: (23) Failure writing output to destination

You can fix running this command after create the alias:

source ~/.bash_profile

So, run the curl command.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment