On OS X
Using MAMP
Enter the command which php
in the terminal to see which version of PHP you are using. If it's not the PHP version from MAMP, the $PATH variable used by Bash will need to be updated.
First, you should use command "cd /Applications/MAMP/bin/php" to check which php version from MAMP and take note of the version (eg, php5.6.7).
Once you know the version, you should edit the ~/.bash_profile
file (that is, the .bash_profile
that is in your home directory) and add an export line:
export PATH=/Applications/MAMP/bin/php/php5.6.7/bin:$PATH
Make sure that you replace php5.6.7 with the version of PHP that you have selected in MAMP.
Once the file has been saved, make sure that you close close your Terminal and open it again. Once that has been done, you will be using the PHP that ships with MAMP.
One way to easily find what the line should be that you need to put inside your .bash_profile
is to run the following command inside your terminal:
echo export PATH=`cat /Applications/MAMP/conf/apache/httpd.conf \
| grep php | grep -i LoadModule | head -n1 \
| sed -e 's/^[^\/]*\/\(.*\)\/mod.*/\/\1/'`/bin:\$PATH
Copying and pasting those three lines into your terminal will correctly output the PHP version that has been selected inside the MAMP control panel.
Using Homebrew/MacPorts
Make sure that your path
contains /usr/local/bin/
(Homebrew) or /opt/local/bin
(MacPorts) if you are using PHP that comes with either of these two package managers.
Checking the PHP path with MacPorts
You can find the exact location of PHP using MacPorts with the following command:
port contents php70 | grep bin/php
Note that you should replace php70
with the version of PHP that you have installed.
Check the PHP path with Homebrew-php
Homebrew-php (https://github.com/Homebrew/homebrew-php) is a tap that has various different versions of PHP.
You can find the exact location of PHP using Homebrew with the following command:
brew --prefix homebrew/php/php56
Note that you should replace php56
with the version of PHP that you have installed.