简体   繁体   English

composer update 和 composer install 报错怎么办?

[英]What todo when composer update and composer install give error ?

I run composer install I got this error, telling me to use composer update我运行composer install我收到这个错误,告诉我使用composer update

Loading composer repositories with package information
Installing dependencies (including require-dev) from lock file
Warning: The lock file is not up to date with the latest changes in composer.json. You may be getting outdated dependencies. Run update to update them.
Your requirements could not be resolved to an installable set of packages.

  Problem 1
    - Installation request for doctrine/inflector v1.3.0 -> satisfiable by doctrine/inflector[v1.3.0].
    - doctrine/inflector v1.3.0 requires php ^7.1 -> your PHP version (7.0.25) does not satisfy that requirement.
  Problem 2
    - Installation request for symfony/css-selector v4.0.3 -> satisfiable by symfony/css-selector[v4.0.3].
    - symfony/css-selector v4.0.3 requires php ^7.1.3 -> your PHP version (7.0.25) does not satisfy that requirement.
  Problem 3
    - Installation request for symfony/event-dispatcher v4.0.3 -> satisfiable by symfony/event-dispatcher[v4.0.3].
    - symfony/event-dispatcher v4.0.3 requires php ^7.1.3 -> your PHP version (7.0.25) does not satisfy that requirement.
  Problem 4
    - Installation request for doctrine/instantiator 1.1.0 -> satisfiable by doctrine/instantiator[1.1.0].
    - doctrine/instantiator 1.1.0 requires php ^7.1 -> your PHP version (7.0.25) does not satisfy that requirement.
  Problem 5
    - doctrine/inflector v1.3.0 requires php ^7.1 -> your PHP version (7.0.25) does not satisfy that requirement.
    - laravel/framework v5.5.32 requires doctrine/inflector ~1.1 -> satisfiable by doctrine/inflector[v1.3.0].
    - Installation request for laravel/framework v5.5.32 -> satisfiable by laravel/framework[v5.5.32].

I run composer update , I got this我运行composer update ,我得到了这个

Loading composer repositories with package information
Updating dependencies (including require-dev)
Your requirements could not be resolved to an installable set of packages.

  Problem 1
    - doctrine/dbal v2.6.3 requires php ^7.1 -> your PHP version (7.0.25) does not satisfy that requirement.
    - doctrine/dbal v2.6.2 requires php ^7.1 -> your PHP version (7.0.25) does not satisfy that requirement.
    - doctrine/dbal v2.6.1 requires php ^7.1 -> your PHP version (7.0.25) does not satisfy that requirement.
    - doctrine/dbal v2.6.0 requires php ^7.1 -> your PHP version (7.0.25) does not satisfy that requirement.
    - Installation request for doctrine/dbal ^2.6 -> satisfiable by doctrine/dbal[v2.6.0, v2.6.1, v2.6.2, v2.6.3].

Now what should I do?现在我该怎么办?

This is what I have in composer.json这就是我在composer.json中的内容

cat composer.json猫作曲家.json

{
    "name": "laravel/laravel",
    "description": "The Laravel Framework.",
    "keywords": ["framework", "laravel"],
    "license": "MIT",
    "type": "project",
    "require": {
        "php": ">=7.0.0",
        "anouar/paypalpayment": ">=3.0",
        "doctrine/dbal": "^2.6",
        "fideloper/proxy": "~3.3",
        "guzzlehttp/guzzle": "^6.3",
        "intervention/image": "^2.4",
        "laravel/framework": "5.5.*",
        "laravel/tinker": "~1.0",
        "spatie/laravel-newsletter": "^4.1",
        "srmklive/paypal": "~1.0"
    },
    "require-dev": {
        "filp/whoops": "~2.0",
        "fzaninotto/faker": "~1.4",
        "mockery/mockery": "~1.0",
        "phpunit/phpunit": "~6.0"
    },
    "autoload": {
        "classmap": [
            "database/seeds",
            "database/factories"
        ],
        "psr-4": {
            "App\\": "app/"
        },
        "files": ["app/Http/Helper.php"]
    },
    "autoload-dev": {
        "psr-4": {
            "Tests\\": "tests/"
        }
    },
    "extra": {
        "laravel": {
            "dont-discover": [
            ]
        }
    },
    "scripts": {
        "post-root-package-install": [
            "@php -r \"file_exists('.env') || copy('.env.example', '.env');\""
        ],
        "post-create-project-cmd": [
            "@php artisan key:generate"
        ],
        "post-autoload-dump": [
            "Illuminate\\Foundation\\ComposerScripts::postAutoloadDump",
            "@php artisan package:discover"
        ]
    },
    "config": {
        "preferred-install": "dist",
        "sort-packages": true,
        "optimize-autoloader": true
    }
} 

I faced the same issue few days ago I fixed it by faking the php version in my composer.json file [Not recommended] .几天前我遇到了同样的问题,我通过在我的 composer.json 文件[不推荐] 中伪造 php 版本来修复它。

"config": {
        "preferred-install": "dist",
        "sort-packages": true,
        "optimize-autoloader": true,
        "platform" : {
            "php": "7.1"
        }
    }

For more details read this有关更多详细信息,请阅读

Or you can execute composer update/install commands with --ignore-platform-reqs flag as shown below或者您可以使用 --ignore-platform-reqs 标志执行 composer update/install 命令,如下所示

composer update --ignore-platform-reqs作曲家更新 --ignore-platform-reqs

You need to install them one by one.您需要一一安装它们。 In Ubuntu you can use apt for it.在 Ubuntu 中,您可以使用 apt。

For example:例如:

sudo apt search inflector

You will see a package related to you version of PHP. Then just do normal installation of it via:您将看到与您的 PHP 版本相关的 package。然后通过以下方式进行正常安装:

sudo apt install php-symfony-inflector

And so on...等等...

You have a few options to tackle this, but all of them are highly dependant on the environment you are trying to run the command.您有几个选项可以解决这个问题,但所有选项都高度依赖于您尝试运行命令的环境。

Let's assume that the composer file is from a 3rd piece of code, if they set the minimum php version it is ok to assume they did so for a reason.让我们假设作曲家文件来自第三段代码,如果他们设置了最低 php 版本,则可以假设他们这样做是有原因的。 I would not try and circumvent this error by faking the version or changing the requirements.我不会尝试通过伪造版本或更改要求来规避此错误。

If you have access, you could:如果您有权访问,您可以:

  1. update the php version on your environment在您的环境中更新 php 版本
  2. run this in an docker container that has the required versions for your project.在具有项目所需版本的 docker 容器中运行它。
  3. install a php-fpm version that will match what the requirement is.安装符合要求的 php-fpm 版本。

With the update option (1) you have to make sure that any other projects that run on the environment don't have compatibility issues with the version you may be updating to.使用更新选项 (1),您必须确保在环境中运行的任何其他项目与您可能更新到的版本没有兼容性问题。 The docker option (2) is in my opinion the safest one, but you'll have to do some reading on how to set it up (assuming your runing on linux: https://docs.docker.com/engine/install/ ). docker 选项 (2) 在我看来是最安全的选项,但您必须阅读一些有关如何设置它的信息(假设您在 linux 上运行: https://docs.docker.com/engine/install/ ). and the last one (3) requires you to setup a php-fpm and then make sure that your virtual host runs with the correct php to make sure you are running on the correct version ( https://www.digitalocean.com/community/tutorials/how-to-run-multiple-php-versions-on-one-server-using-apache-and-php-fpm-on-ubuntu-18-04 )最后一个 (3) 要求您设置 php-fpm,然后确保您的虚拟主机使用正确的 php 运行,以确保您运行的版本正确( https://www.digitalocean.com/community /tutorials/how-to-run-multiple-php-versions-on-one-server-using-apache-and-php-fpm-on-ubuntu-18-04 )

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM