Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Instructions on how to change preinstalled Mac OS X PHP to MAMP's PHP Installation and then install Composer Package Management

Change default Mac OS X PHP to MAMP's PHP Installation and Install Composer Package Management

Instructions to Change PHP Installation

First, Lets find out what version of PHP we're running (To find out if it's the default version).

To do that, Within the terminal, Fire this command:

which php

This should output the path to the default PHP install which comes preinstalled by Mac OS X, by default it has to be (Assuming you've not changed it before):


Now, We just need to swap this over to the PHP that is installed with MAMP, which is located at /Applications/MAMP/bin/php/php5.4.10/bin (MAMP 2.1.3)

To do this, We need to edit the .bash_profile and add the MAMP version of PHP to the PATH variable.

Follow these simple steps:

  1. Within the Terminal, run vim ~/.bash_profile

  2. Type i and then paste the following at the top of the file:

     export PATH=/Applications/MAMP/bin/php/php5.4.10/bin:$PATH
  3. Hit ESC, Type :wq, and hit Enter

  4. In Terminal, run source ~/.bash_profile

  5. In Terminal, type in which php again and look for the updated string. If everything was successful, It should output the new path to MAMP PHP install.

  6. In case it doesn't output the correct path, try closing the terminal window (exit fully) and open again, it should apply the changes (Restart in short).

Install Composer Package Management

Now you can fire the command to install the composer globally (So you can access it from anywhere):

$ curl -sS | php -- --install-dir=/usr/local/bin --filename=composer

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


It'll show you the current version and a list of commands you can use if the installation was successful.

These are good instructions but for some reason my path is not updating. I'm comfortable with command line and vim but after running source ~/.bash_profile I still get /usr/bin/php

My MAMP is running PHP 5.4.3 and I'm on OSX 10.7.5

Thanks for posting.

Still getting the same /usr/bin/php

thanks for the instruction, help's me a lot setting up laravel on mac :)

zeratool commented May 8, 2014

@xulfiqarameen edit your ~/.bash_profile replace it with your homebrew php install.

zeratool commented May 8, 2014

@JonWalkerTN if you;re saying under apache via browser, you must edit "/etc/apache2/httpd.conf" and look for the line "LoadModule php5_module" and replace it with your php homebrew install.

@JonWalkerTN are you using oh-my-zsh by any chance? That's what I'm using, and instead of editing ~/.bash_profile, edit your ~/.zshrc instead, and add the exact same lines. Then run source ~/.zshrc. That solved the issue for me.

Thanks a lot, 2 hours of pain solved!

It worked!! thanks!

phpguru commented Dec 15, 2014

Yosemite comes with Apache 2.4 & PHP 5.5 preinstalled. You don't need MAMP, only MySQL or MariaDB.

Regardless, you can use PHP 5.5, PHP 5.4 or PHP 5.3 as needed. Try the following...

sudo mv /usr/local/bin/php /usr/local/bin/php55
sudo mv /usr/bin/php /usr/bin/php55

Install PHP 5.4

brew install php54 php54-mcrypt php54-mysql

Install PHP 5.3

brew unlink php54
brew install php53 php53-mcrypt php53-mysql

Switch to PHP 5.4

brew unlink php53
brew link php54

Switch to PHP 5.5

brew unlink php54
brew unlink php53
sudo ln -s /usr/local/bin/php55 /usr/local/bin/php
sudo ln -s /usr/bin/php55 /usr/bin/php

Many thanks - very helpful

ghost commented Feb 28, 2015

Solved my problems :). Trying to install Laravel5 on a MAMP Pro server, and had all sorts of problems, especially (missing mcrypt).
Using this solution so it uses MAMP's php, everything now works.

After following the steps which, vim command not working. Please help me to solve this


These are some pretty old instructions. I've already moved to Vagrant setup for the dev environment. You guys need to explore Vagrant really! Much better there.

You can use this awesome vagrant box called Homestead. Not limited to Laravel, can be used for anything.

Dat-TSC commented Jun 23, 2015

You have to close then re-open the terminal to see the effect. Cheers.

oh man i love you so much

Tank you !! very helpful

Thank you so much! Nothing I was doing was working until this. I was about ready to punch monkeys in the face. This write up saved a bunch of monkeys from being punched.

cord commented Feb 9, 2016

for me this was necessary to set the php version:

vim ~/.profile


source ~/.profile

then php -v shows the correct php is used

@cord thank you for your comment, it works for me as well.

This switches it for the cli but apache might still be using the old php.

kslusarczyk89 commented May 18, 2016 edited

Im using oh-my-zsh and according to @zhiachong advice i did the following instructions with ~/.zshr but it didn't work. After typing which php in iterm i still get /usr/bin/php. Actually when I edit bash_profile it works fine but after closing console I have to constantly type those instructions. Any advise?

@cord thank you it helped me.

Wow, Thanks. It took forever to find these instructions. Everyone said to update ~/.profile.. and it never worked. This guide was truly amazing!

Thanks A lot

zhiachong Thanks for the answer.

I was using oh-my-zsh . so I had to edit ~/.zshrc

Thank you! :)

I have created a script that lets you select the version of php you would like to run and creates a sym-link to that version. You can find it here and I have a blog about how to put it to use which you can find here if anyone is interested.

LTroya commented Sep 9, 2016

It works like a charm!


ghost commented Sep 20, 2016

thanks alot !

@irazasyed - thank you very much, you helped me in ways no other resource online seemed to be able to. Appreciate you posting this very very much.

@irazasyed : I love you !

Thank you!

Thanks it is solved my problem in mac too

Sifoon commented Nov 22, 2016

@irazasyed : Thanks very much ! clean & clear and the most important it works wellll.

Great stuff!! Thanks a lot man. It's hard to find reliable AMP setups for Mac OS X.
I myself am interested in eventually uninstalling MAMP in favour of updating the preinstalled Apache and PHP along with an install of MySQL, but this was an awesome work around for the time being! 👍

Can someone share the commands to set it back to default?

Thank you so much

i have solved with this
vim ~/.bash_profile

export XAMPP_HOME=/Applications/XAMPP
export PATH=${XAMPP_HOME}/bin:${PATH}
export PATH

saved !

working perfect :-)

doub1ejack commented Feb 20, 2017 edited

If you're using macport you can just do this:
$ sudo port select php php56

Replace php56 with whatever version you want to switch to. No need to worry about the OS-installed version.

Great ! Thanks a lot

rryybbaa commented Mar 4, 2017

This works for me. Thanks

Thanks, @zhiachong This works for me.
Using oh-my-zsh by any chance? That's what I'm using, and instead of editing ~/.bash_profile, edit your ~/.zshrc instead, and add the exact same lines. Then run source ~/.zshrc. That solved the issue for me.

This worked for me. Thanks. I just changed the PHP version that I was using.

davidLpt commented Apr 28, 2017 edited

I follow the procedure and the change of path is ok. But '$ curl -sS | php -- --install-dir=/usr/local/bin --filename=composer' give me an curl: (56) SSLRead() return error -9806....... anybody had and solved the same issue?

UPDATE: I did a manual install

dinkarprajapati commented Apr 29, 2017 edited

To change the php path in mac Sierra, i did the steps mentioned but still when i run

which php

I still get


I tried restarting terminal and even mac but it is still the same path. I have followed every steps

  • change bash_profile

export PATH="/Applications/XAMPP/xamppfiles/bin/php-7.0.15:$PATH"

  • did source ~/.bash_profile

Any idea why the path is so stubborn

For XAMPP, path I used was wrong. It should be

export PATH="/Applications/XAMPP/bin:$PATH"

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