59

On my local machine, I have php v7.0.3. A project of mine has a dependency on php v5.5.

So as expected, a simple run of composer install crashes:

Your requirements could not be resolved to an installable set of packages.

  Problem 1
    - This package requires php ~5.5 but your PHP version (7.0.3) does not satisfy that requirement.

I know I can ignore the platform via:

composer install --ignore-platform-reqs

yet I often forget to add the flag. Yet since the application runs inside a docker container, a mismatching php can install the dependencies just as fine.

So I am wondering if there is a way to make my local composer always assume --ignore-platform-reqs in order to not having to type it.

I like to avoid setting an alias and have it work on composer config level.

3
  • Could you show me how you do that please? I only have 1 laravel package where I can't install it for the life of me. Yeah, I know i can ignore the platform reqs but it seems like you know how to!
    – Eduardo
    Feb 2, 2021 at 23:59
  • @Eduardo Without context it's hard to know what you want to achieve. You can ask as follow-up question linking to this one. It's best you have a reproducable and minimal example of your problematic composer.json and local php version.
    – k0pernikus
    Feb 4, 2021 at 16:34
  • No worries I was able to fix my issue, thanks for replying you sir are good man! :-) Cheers!
    – Eduardo
    Feb 4, 2021 at 17:50

5 Answers 5

46

It's recommended to fake the PHP version, rather than to ignore platform requirements. Add:

"platform":{"php":"5.5"}

to your ~/.composer/config.json or use composer config -g -e to edit it.

An example of a config to fake the PHP version and an extension:

{
    "config": {
        "platform":{
            "php": "8.1",
            "ext-bcmath": "8.1"
        }
    }
}

More options about the config's platform section can be found in the Composer docs.

UPDATE: starting from v2.3.0 you can use environment variables. Please see Yakatz' answer

7
  • Could you please provide a full config.json example? It seems that for me the config is currently ignored.
    – k0pernikus
    Feb 8, 2016 at 16:42
  • hmm, just tested it on ubuntu. composer show --platform confirms Package overridden via config.platform (actual:..., and when I fake php as 3.2, composer update yelds - This package requires php >=5.2 but your PHP version (3.2) does not ....
    – Alex Blex
    Feb 8, 2016 at 17:09
  • I just realized that I have both a requirement on php ~5.5 and 5.4, so I guess that I am in a deadlock when choosing between the two. Yet what I found particular interesting is that composer config -e open the composer.json file of the project instead of the config.json of composer's home.
    – k0pernikus
    Feb 8, 2016 at 17:30
  • Sorry, typo, as always =(. It is global config of course: composer config -g -e. The one which is user-specific. How do you resolve this deadlock on other environments?
    – Alex Blex
    Feb 8, 2016 at 17:38
  • We are using hhvm :D Not ideal, but it seems that composer does not check Plattform
    – k0pernikus
    Feb 8, 2016 at 17:41
39

A new feature in Composer v2 allows you to selectively ignore platform requirements.

composer install --ignore-platform-req=php

Composer already has a --ignore-platform-reqs option (notice the s in reqs), but it ignores all platform requirements, including PHP version, extensions (ext-*), and composer-plugin-api.

The new --ignore-platform-req option can be used to set specific requirements that Composer can ignore.

18

Composer now supports (as of version 2.3.0) checking an environment variable to set --ignore-platform-reqs.

Create an environment variable COMPOSER_IGNORE_PLATFORM_REQS=1 to ignore all or COMPOSER_IGNORE_PLATFORM_REQ=something to ignore something as a requirement.

1
  • 4
    This is should be the best answer as of 2022 Aug 29, 2022 at 15:22
11

You can add alias composer="composer --ignore-platform-reqs" to your .bash_profile but it will break commands that don't recognize this option (eg. composer outdated).

Personally I have:

alias composer="composer --ignore-platform-reqs"
alias composer_orig="/usr/local/bin/composer"

Because most of the time I want --ignore-platform-reqs, but still I can use composer_orig each time I see

[Symfony\Component\Console\Exception\RuntimeException]

The "--ignore-platform-reqs" option does not exist.

1
  • 3
    you can bypass alias by running \composer.
    – Cicatrice
    Nov 7, 2022 at 13:21
2

On Windows, update composer.bat (under C:\ProgramData\ComposerSetup\bin) and add --ignore-platform-reqs to the composer command.

To update, you may open text-editor as administrator > Ctrl + O > Open composer.bat

If you don't want the change it globally for all your projects, create a new .bat file and use it in PHPStorm > Settings > composer

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.