How to use MAMP's version of PHP instead of the default on OSX
I have created a symlink at the original php location.
1. Locate your osx php version with:
which php
The result should be:
/opt/local/bin/php
2. Backup (move) your original php binary:
sudo mv /opt/local/bin/php /opt/local/bin/php.bak
3. Create the symlink:
sudo ln -s /Applications/MAMP/bin/php/php5.4.4/bin/php /opt/local/bin/php
4. Run your new php version:
php -v
PS:
In order for this to work on El-Capitan
- Reboot your Mac to RecoveryMode (hold Cmd+R on boot)
- Open Terminal and enter:
csrutil disable
- Reboot
- either :
sudo ln -s /Applications/MAMP/bin/php/php5.4.4/bin/php /opt/local/bin/php
orsudo ln -s /Applications/MAMP/bin/php/php5.4.4/bin/php /usr/bin/php
- Reboot again to RecoveryMode and re-enable security:
csrutil enable
I would not recommend trying to modify the default version of PHP that is called on the command line. Doing so may break other parts of your system as well as provide you with problems in the future, should you decide to upgrade your OS.
There is an alternative that may meet your needs. You can create an alias to your copy of MAMP's php 5.3. In my case I named the alias phpmamp. Open your terminal and type:
alias phpmamp='/Applications/MAMP/bin/php5.3/bin/php'
Now, typing phpmamp at the command line will launch the MAMP php interperter. Verify this by typing:
phpmamp --help
You will most likely want to store this, and any other alias, in a ~/.bash_profile
This will allow the aliases to persist across reboots. Otherwise, the alias should only last for the particular terminal session you are in. More information about creating a .bash_profile
file can be found here:
http://www.redfinsolutions.com/redfin-blog/creating-bashprofile-your-mac
I prefer not to tamper with the current files, so I just prepend the MAMP PHP bin folder to the $PATH
env variable.
You can edit ~/.bash_profile
and add the the following line to the top
export PATH="/Applications/MAMP/bin/php/php5.6.1/bin:$PATH"
Just change the PHP version to the current version you are using.
Don't forget to do source ~/.bash_profile
after you edit the file.