skip to Main Content

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!

2

Answers


  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.

    Login or Signup to reply.
  2. 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"
            }
        }
    }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search