Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Composer: prevent updating packages that require higher PHP version

I'm using the doctrine/dbal (v2.4.*) package in my PHP project. My production server runs PHP v5.6.

I ran composer update this morning which updated my composer.lock file. Now, when I'm deploying to production, I see this:

 Problem 1
    - Installation request for doctrine/inflector v1.2.0 -> satisfiable by doctrine/inflector[v1.2.0].
    - doctrine/inflector v1.2.0 requires php ^7.0 -> your PHP version (5.6.14) does not satisfy that requirement.
  Problem 2
    - doctrine/inflector v1.2.0 requires php ^7.0 -> your PHP version (5.6.14) does not satisfy that requirement.
    - doctrine/common v2.4.3 requires doctrine/inflector 1.* -> satisfiable by doctrine/inflector[v1.2.0].
    - Installation request for doctrine/common v2.4.3 -> satisfiable by doctrine/common[v2.4.3].

Specifically these:

doctrine/common v2.4.3 requires doctrine/inflector 1.* -> satisfiable by doctrine/inflector[v1.2.0].

doctrine/inflector v1.2.0 requires php ^7.0 -> your PHP version (5.6.14) does not satisfy that requirement

This means, that even if dbal is old, it requires the newest common, and common requires the newest inflector package. Problem is that inflector started depending on PHP7 to run.

Is there any way in Composer to limit updating of the packages to those supported by specific PHP version? Like saying: "Please update what you can, but only if the server's PHP version is sufficient."

like image 899
lesssugar Avatar asked Apr 18 '26 07:04

lesssugar


1 Answers

Use the platform option in your composer.json file to define the PHP version your production environment is using like this:

{
    "config": {
        "platform": {
            "php": "5.6.14"
        }
    }
}

see https://getcomposer.org/doc/06-config.md#platform

like image 107
xabbuh Avatar answered Apr 20 '26 08:04

xabbuh



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!