10

I'm trying to install a package via Composer that requires PHP 5.6.0. My MAC is running PHP 5.5.31 but MAMP runs PHP 7.0. The package will not download because of the PHP requirement is not met since it's looking at my macOS version, not the version I actually use with MAMP. How can I get around this?

insertusernamehere
  • 23,204
  • 9
  • 87
  • 126
Packy
  • 3,405
  • 9
  • 50
  • 87
  • 2
    What version of php is showing when you run `php -v` in the terminal? If it's the osx version instead of the mamp version, i suggest that you set your mamp version as the default php version. Look at here http://stackoverflow.com/questions/4262006/how-to-use-mamps-version-of-php-instead-of-the-default-on-osx – Peter Apr 13 '16 at 14:41
  • 5.5.31 is the one I got when doing `php -v` – Packy Apr 13 '16 at 14:46
  • though enabling 'activate command line shortcuts for the selected PHP version' shows MAMP PHP when running `which php`, composer picks up Mac default PHP. I had to explicitly add `export PATH` (below answer) to the composer to pick up MAMP's. – vijaycs85 Nov 30 '20 at 13:24

3 Answers3

29

MAMP's PHP is located here:

/Applications/MAMP/bin/php/php7x.x/bin/

The default OSX PHP is located in

/usr/bin/php

/usr/bin is in PATH variable by default.

When you want OSX to use the MAMP version instead, you need to add /Applications/MAMP/bin/php/php7.x.x/bin/ to your PATH variable.

Simply edit ~/.bash_profile in your terminal and type

vim ~/.bash_profile

if you cannot find ~/.bash_profile then you have to create one with

touch ~/.bash_profile

and add the following line to end of the file:

export PATH=/Applications/MAMP/bin/php/php7.x.x/bin/:$PATH

You just have to look at the correct version of your MAMP's php and replace the x.x from the example above with that correct number. (e.g. 7.0.2)

If that went fine, relaunch your terminal.app and do php -vagain. Now you have to see the new version.

After that try to install the composer package again! Good luck

Help source: how-to-override-the-path-of-php-to-use-the-mamp-path

Community
  • 1
  • 1
Peter
  • 1,240
  • 2
  • 13
  • 22
2

This was easy to me:

First backup system php sudo mv /usr/bin/php /usr/bin/~php

Then crate a symbolic link from /Applications/MAMP/bin/php/phpX.x.x/bin/php to /usr/bin/php using this: sudo ln -s /Applications/MAMP/bin/php/phpX.x.x/bin/php /usr/bin/php. Now you have your mamp php (with its config) available everywhere.

Jean Paul CP
  • 253
  • 2
  • 10
  • Note: for backup folder into ~php the macos will not allow. For it use following https://stackoverflow.com/questions/32659348/operation-not-permitted-when-on-root-el-capitan-rootless-disabled – Zohaib Yunis Apr 10 '22 at 11:06
1

If you type 'which php' into Terminal it'll show you where it's looking for PHP. I'm guessing there are 2 different versions of PHP installed into different directories. In which case you might be able to use a bash script to set the correct path to the PHP version you want?

I've had similar issues on my Mac where I've installed software like git, but it's looking elsewhere for it (e.g. the version bundled with Xcode)

Andy F
  • 235
  • 6
  • 16