25

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.

k0pernikus
  • 41,137
  • 49
  • 170
  • 286
  • 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 02 '21 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 04 '21 at 16:34
  • No worries I was able to fix my issue, thanks for replying you sir are good man! :-) Cheers! – Eduardo Feb 04 '21 at 17:50

4 Answers4

22

It's recommended to fake php version, rather than 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 sufficient config to fake php version:

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

It may have much more options though.

Alex Blex
  • 25,038
  • 5
  • 33
  • 63
  • Could you please provide a full `config.json` example? It seems that for me the config is currently ignored. – k0pernikus Feb 08 '16 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 08 '16 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 08 '16 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 08 '16 at 17:38
  • We are using hhvm :D Not ideal, but it seems that composer does not check Plattform – k0pernikus Feb 08 '16 at 17:41
  • If you want this tied to your specific project or to work without having composer installed globally (like me), you can place the config block in your composer.json file – MrGlass Jun 05 '17 at 16:55
7

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.

pamelus
  • 2,180
  • 1
  • 17
  • 27
3

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.

Ismoil Shifoev
  • 3,486
  • 1
  • 18
  • 21
0

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

Aranya Sen
  • 644
  • 6
  • 12