Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
297 views
in Technique[技术] by (71.8m points)

Reference - Composer error "Your PHP version does not satisfy requirements" after upgrading PHP

After updating PHP from 7.4 to 8.0, I ran composer update on my existing project, and got an error like this:

  • acme/some-package[1.0.0, ..., 1.4.0] requires php ^5.6.4 || ^7.0 -> your php version (8.0.3) does not satisfy that requirement.

What does this mean, and how do I fix it?

(This is a reference answer intended to cover a frequently encountered issue. The scenario is just an example. See also: "How to explain Composer's error log?")

Question&Answers:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

The Problem

As well as the versions of other packages they require, Composer packages can specify the versions of PHP which they support.

While resolving the versions of packages to install, Composer has to find versions which match all the constraints in place:

  • The version constraints you've specified for dependencies in your composer.json
  • The version constraints each package has specified for its dependencies
  • The PHP versions each package supports

If there is no package that satisfies all of those constraints, you will get an error.

Common Confusions

Note that the version constraint for PHP version follows the same rules as other composer constraints. So a constraint of ^7.0 means "any version of 7.x above 7.0", and does not include 8.0.

The Solution

To solve the problem, you need to relax one of those constraints:

  1. Look at the package mentioned in the error message (acme/some-package in the example) and find it on Packagist (or whatever custom package source you have configured).
  2. See if a newer version exists that supports your PHP version.
  3. If it doesn't, you'll need to find out what's needed to add that support. This might mean checking out the project directly, running its tests, and submitting a patch to mark it as compatible with the new version.
  4. If (when) support has been added, you'll need to make sure your composer.json, and other packages you depend on, don't exclude that new version. For instance, if you currently depend on acme/some-package version ^1.0, but PHP 8.0 is only supported from version 2.2.0 onwards, you'll need to change your constraint to ^2.2, and make sure your application is still compatible.

Temporary Workaround

Sometimes, you're pretty sure your application will run fine with the same versions of packages as you were previously using. In that case, you can use the platform configuration variable in your composer.json to pretend you're still using the old version. This should only be done as a temporary workaround or for testing as it means packages will be installed which may be completely broken on your new PHP version.

For example:

{
    "config": {
        "platform": {
             "php": "7.4.999"
        }
    }
}

See also "Override PHP base dependency in composer"


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...