Change the PHP Path to Mamps PHP

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.

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

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

Install Composer on MAMP on Windows

  1. Open php.ini located in your "\MAMP\conf\" folder or copy the php.ini into a \MAMP\bin\php\php[your PHP version number]\
  2. Find "extension=php_openssl.dll"
  3. ;extension=php_openssl.dll - remove ";"
  4. Restart your MAMP , extension should be loaded after that.

PHP errors in a new MAMP

Preface your PHP code with this. It will force error display.

ini_set('display_errors', 'On');
error_reporting(E_ALL);

Also check your .ini files in the following locations:

Applications/MAMP/bin/php/(PHP version)/conf/php.ini

Applications/MAMP/conf/php/(PHP version)/conf/php.ini

They should both be set for:

display_errors = On

EDIT: I should clarify this, as it may be a point of confusion: You should restart your MAMP server when the changes are complete.

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.



Related Topics



Leave a reply



Submit