How to Override the Path of PHP to Use the Mamp Path

How to override the path of PHP to use the MAMP path?

Everytime you save MAMP config (PHP section), it saves the current version of PHP on ~/.profile file and creates the alias for php, pear and pecl, to point to the current configured version. (Note: you need to check "Make this version available on the command line" option in MAMP)

However, you need to refresh your terminal (open another session) to get this file refreshed. You can also type source ~/.profile to refesh the aliases manually.

If you want to extract this curerent version in a PHP_VERSION variable - as commented above - for further use, you can do:

export PHP_VERSION=`grep "alias php" ~/.profile | cut -d"/" -f6 | cut -c4-`

And then you'll have $PHP_VERSION available with the current version of MAMP.

Finally, if you want to run your php using the current configured version on mamp, you just need to add to your ~/.bash_profile the following:

export PHP_VERSION=`grep "alias php" ~/.profile | cut -d"/" -f6 | cut -c4-`
export PHPRC="/Library/Application Support/appsolute/MAMP PRO/conf/" #point to your php.ini folder to use the same php settings
export PATH=/Applications/MAMP/bin/php/php$PHP_VERSION/bin:$PATH

Now, even script that relies on /usr/bin/env php will read the correct version from Mamp config.

How to use MAMP's version of PHP instead of the default on OSX

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

change the PHP path to MAMPs PHP

Create a file called .bash_profile on your home directory (if you don't have this file already), and add this to the file:

export PATH=/Applications/mamp/bin/php5.3/bin:$PATH

Then quit and relaunch Terminal.app

Change PATH Environment Variable in MAMP

In MAMP 4.0.6 for OSX I was able to update the Apache Environment Path by doing the following:

First check /Applications/MAMP/Library/bin/apachectl for a line with the comment:

#pick up any necessary environment variables

Just below this line you should see a path to where MAMP will load environment variables.

Mine said:

/Applications/MAMP/Library/bin/envvars

In the /Applications/MAMP/Library/bin path you should see a file named envvars_.

Copy this file and rename to envvars and add the following line:

export PATH="/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin"

Now restart your MAMP servers. The phpinfo should now have the updated path information.

MAMP and PHP on Terminal

The problem is working with PHP command line is not found with ZSH, it gets a message: zsh: command not found: php.

So working with older BASH instead of ZSH it works fine.

Where does MAMP keep its php.ini?

Note: If this doesn't help, check below for Ricardo Martins' answer.


Create a PHP script with <?php phpinfo() ?> in it, run that from your browser, and look for the value Loaded Configuration File. This tells you which php.ini file PHP is using in the context of the web server.



Related Topics



Leave a reply



Submit