Skip to content

Instantly share code, notes, and snippets.

Last active January 30, 2024 02:30
Show Gist options
  • Save kkirsche/5710272 to your computer and use it in GitHub Desktop.
Save kkirsche/5710272 to your computer and use it in GitHub Desktop.
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

StonehengeCreations commented Mar 2, 2023

If you are using MAMPRO with PHP 8.0.8, why are you telling macOS to use PHP 7.1.12?

Composer will then still use version 7.1.12 to require or update.

PHP_VERSION=`ls /Applications/MAMP/bin/php/ | sort -n | tail -2 | head -1`
export PATH=/Applications/MAMP/bin/php/${PHP_VERSION}/bin:$PATH

Then source ~./bash_profile

This will tell macOS (and anything using the php command) to use the latest installed PHP version within MAMPRO.

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