Geoff Maddock
Geoff Maddock

Reputation: 1812

Composer: How to get composer to install a version that depends on an older PHP?

Is there a way to tell composer to not install any dependencies that require a PHP version that is lower than the version actually installed? I tried using:

    "platform": {
        "php": "7.0.19"
    }

And running

composer install

But it didn't revert the dependencies to older versions (or do anything at all).

Here's my overall case:

I have a Symfony project that I'm working on in two environments.

One that has PHP 7.0.19 and one that has PHP 7.1.5.

The project was started on the server using PHP 7.1.5.

When I try to deploy the project on the server with 7.0.19, and run composer install, it throws an error, saying there is no resolvable set of packages:

[geoff.maddock@myserver project]$ composer install --no-scripts Loading composer repositories with package information Installing dependencies (including require-dev) from lock file Your requirements could not be resolved to an installable set of packages.

  Problem 1
    - Installation request for ocramius/proxy-manager 2.1.1 -> satisfiable by ocramius/proxy-manager[2.1.1].
    - ocramius/proxy-manager 2.1.1 requires php ^7.1.0 -> your PHP version (7.0.19) does not satisfy that requirement.   Problem 2
    - doctrine/migrations v1.5.0 requires ocramius/proxy-manager ^1.0|^2.0 -> satisfiable by ocramius/proxy-manager[2.1.1].
    - doctrine/migrations v1.5.0 requires ocramius/proxy-manager ^1.0|^2.0 -> satisfiable by ocramius/proxy-manager[2.1.1].
    - ocramius/proxy-manager 2.1.1 requires php ^7.1.0 -> your PHP version (7.0.19) does not satisfy that requirement.
- Installation request for doctrine/migrations v1.5.0 -> satisfiable by doctrine/migrations[v1.5.0].

So the version of ocramius/proxy-manager that was installed on 7.1.5 meets the second half of the

"^1.0|^2.0"

requirement, but can't be met on 7.0.19.

If I can tell composer to only install ^1.0, then it should work on both platforms. Is there a way to do that and then tell composer to reinstall the dependencies based on that change?

Upvotes: 2

Views: 3896

Answers (1)

localheinz
localheinz

Reputation: 9592

Run

$ composer require ocramius/proxy-manager:~2.0.4

to install the package in a version that will work on both PHP 7.0.19 and PHP 7.1.5.

Note how the ~ operator is used here, as opposed to using the ^ operator: 2.0.4 is the most recent version in the 2.0 line that supports both desired PHP versions, and using the ~ operator in combination with specifying major.minor.patch will only allow updates of patch versions (here, >=2.0.4 and <2.1.0).

2.0.4

requires

  • php: 7.0.0 - 7.0.5 || ^7.0.7

For reference, see:

Upvotes: 2

Related Questions