1

On my local machine I have MAMP PRO running, which allows the change of PHP version per project independently.

Composer is installed on a specific PHP version, but my project aren't.

How would I use composer so that it will either use the PHP version of the local environment, or so that I can easily tell Composer that I am using PHP "x.x.x".

Thank you in advance!

Timberman
  • 647
  • 8
  • 24
  • Does this answer your question? [Force composer to require PHP Version between Version X and Version Y](https://stackoverflow.com/questions/26277151/force-composer-to-require-php-version-between-version-x-and-version-y) – Nico Haase Mar 13 '23 at 12:40
  • Not exactly, but It's good that it's here right now. – Timberman Mar 13 '23 at 13:33
  • Can you share more details about that? The most upvoted answers in that linked question provide the exact same hint that you've accepted in this question – Nico Haase Mar 13 '23 at 13:45
  • The question is obviously not the same. The most upvoted answer there doesn't answer his question, since that he's asked for a version between 2 php versions. – Timberman Mar 13 '23 at 14:05

2 Answers2

1

I believe you're looking for this thing: https://getcomposer.org/doc/06-config.md#platform

{
    "config": {
        "platform": {
            //"php": "/path/to/php or php version"
            "php": "7.0.3"
        }
    }
}
Denis O.
  • 1,841
  • 19
  • 37
-1

You can do this using the composer.phar file downloaded for each project, rather than the global installation of composer. For example

php7.4 composer.phar install or php8.2 composer.phar install or etc.

For downloading composer.phar

php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
php composer-setup.php
php -r "unlink('composer-setup.php');"

ps: don't forget to add composer.phar to gitignore.

DarkShade
  • 103
  • 6
  • Please share more details. Why should running the exact same phar file with different PHP versions require multiple copies of that file? – Nico Haase Mar 13 '23 at 12:40
  • As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Mar 18 '23 at 17:29
  • @NicoHaase Right it's wrong. It is also possible to use `php7.4 /bin/composer install`. But the above answer seems to suit the questioner. – DarkShade Mar 18 '23 at 18:39