Skip to content

Instantly share code, notes, and snippets.

@kkirsche
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 https://getcomposer.org/installer | 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:

composer

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

@gitMomo
Copy link

gitMomo commented Jun 4, 2017

i have the same errors than jasonglisson ...

@MavenConsulting
Copy link

jasonglisson & gitMomo. Once you've added the alias, close down terminal (type "exit") and open a new one... this will reload the bash_profile with the newly added alias as per mynameisrienk comment on Jan 24, 2014 (Although his single curl command didn't work for me). Then continue the process. I was having the same problems, this seemed to fix it for me.

@GESUMAYOR
Copy link

Helped a lot. Thanks and many thumbs up. Saved my ass

@ibrahimtumukunde
Copy link

thank You so much.

@flexscss
Copy link

For zsh
alias -g phpmamp='/Applications/MAMP/bin/php/php5.6.10/bin/php'

@zrshishir
Copy link

After installation when i run 'composer' then it says '-bash: composer: command not found', why ? I can't install composer for this reason.

@nsukonny
Copy link

nsukonny commented Dec 2, 2017

Thanks! Were helpful post!

@Hestabit
Copy link

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

@digeek
Copy link

digeek commented Feb 23, 2018

thanks

@TheBigSteph
Copy link

Thanks

@StonehengeCreations
Copy link

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.

@scorchio
Copy link

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.

@brokenmachine
Copy link

Many thanks for creating this!

@ThomRockwell
Copy link

Wonderfully simple! Thanks so much!

@anabrownee
Copy link

thanks, this worked like a charm!

@bertrandBourgy
Copy link

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

@ty1l3r
Copy link

ty1l3r commented Mar 23, 2020

Thank you !

@francisco83
Copy link

Muchas Gracias!

@fiqriachmada
Copy link

Thanks for the guide

@davidrhoden
Copy link

still working in 2021, thank you

@mosaabramadan
Copy link

thanks alot

@patovd
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.

@hanskuiters
Copy link

hanskuiters commented Oct 11, 2022

On Mac OS Monterey I get this error:
php: No such file or directory

This is my .bash_profile:
alias phpmamp="/Applications/MAMP/bin/php/php8.0.8/bin/php"
alias composer="/usr/local/bin/composer"
export PATH="/Applications/MAMP/bin/php/php7.1.8/bin:$PATH"

MAMP 6.6 with php version 8.0.8.

Any idea to fix this?

Edit: I found the answer.

OSX Monterey has no php by default. You have to tell terminal to use MAMP php. To do that, add this to .bash_profile:
PATH=/Applications/MAMP/Library/bin:/Applications/MAMP/bin/php/php7.1.12/bin:$PATH
and then: source ~/.bash_profile to load the new settings.

@fortsev
Copy link

fortsev commented Nov 14, 2022

On Mac OS Monterey I get this error: php: No such file or directory

This is my .bash_profile: alias phpmamp="/Applications/MAMP/bin/php/php8.0.8/bin/php" alias composer="/usr/local/bin/composer" export PATH="/Applications/MAMP/bin/php/php7.1.8/bin:$PATH"

MAMP 6.6 with php version 8.0.8.

Any idea to fix this?

Edit: I found the answer.

OSX Monterey has no php by default. You have to tell terminal to use MAMP php. To do that, add this to .bash_profile: PATH=/Applications/MAMP/Library/bin:/Applications/MAMP/bin/php/php7.1.12/bin:$PATH and then: source ~/.bash_profile to load the new settings.

Thanks!

@StonehengeCreations
Copy link

If you hard code the file path to a specific PHP version, composer and macOS will use that. Easy check in Terminal is: php -v.
To check which php file is used outside of MAMP: which php.

To prevent the need to edit your bash profile every time you update the PHP version in MAMP, you can call the latest installed PHP version dynamically:

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

@appinlet
Copy link

PATH=/Applications/MAMP/Library/bin:/Applications/MAMP/bin/php/php7.1.12/bin:$PATH

This helped me

@almeidaweliton
Copy link

On Mac OS Monterey I get this error: php: No such file or directory

This is my .bash_profile: alias phpmamp="/Applications/MAMP/bin/php/php8.0.8/bin/php" alias composer="/usr/local/bin/composer" export PATH="/Applications/MAMP/bin/php/php7.1.8/bin:$PATH"

MAMP 6.6 with php version 8.0.8.

Any idea to fix this?

Edit: I found the answer.

OSX Monterey has no php by default. You have to tell terminal to use MAMP php. To do that, add this to .bash_profile: PATH=/Applications/MAMP/Library/bin:/Applications/MAMP/bin/php/php7.1.12/bin:$PATH and then: source ~/.bash_profile to load the new settings.

saved my day

@StonehengeCreations
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