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!

4
  • Does this answer your question? Force composer to require PHP Version between Version X and Version Y Commented Mar 13, 2023 at 12:40
  • Not exactly, but It's good that it's here right now. Commented Mar 13, 2023 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 Commented Mar 13, 2023 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. Commented Mar 13, 2023 at 14:05

2 Answers 2

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"
        }
    }
}
Sign up to request clarification or add additional context in comments.

Comments

-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.

3 Comments

Please share more details. Why should running the exact same phar file with different PHP versions require multiple copies of that file?
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.
@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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.