Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Composer use MAMP PHP Version

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?

like image 307
Packy Avatar asked Apr 13 '16 14:04

Packy


People also ask

What version of PHP does Composer use?

- Root composer. json requires php >=7.4 but your php version (7.3. 14) does not satisfy that requirement.

Does Mamp include PHP?

PHP is a popular web scripting programming language. MAMP PRO installs several versions of the PHP script interpreter. Select which PHP version will be the default version.

Does composer require PHP?

System Requirements#Composer in its latest version requires PHP 7.2.5 to run. A long-term-support version (2.2.x) still offers support for PHP 5.3.2+ in case you are stuck with a legacy PHP version.


2 Answers

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.

like image 163
Jean Paul CP Avatar answered Oct 02 '22 01:10

Jean Paul CP


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

like image 24
Peter Avatar answered Oct 01 '22 23:10

Peter