覆盖 Composer 中的 PHP 基础依赖项

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/32838881/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 23:14:07  来源:igfitidea点击:

Override PHP base dependency in composer

phpcomposer-php

提问by Alex

I try to install Laravel 5.1 on a host which only has PHP 5.5.6. While I asked the customer to upgrade, this might be not possible/feasible.

我尝试在只有 PHP 5.5.6 的主机上安装 Laravel 5.1。虽然我要求客户升级,但这可能是不可能/不可行的。

So I am getting:

所以我得到:

- This package requires php >=5.5.9 but your PHP version (5.5.6)
   does not satisfy that requirement.

on composer.phar install.

composer.phar install

Is there a way to do a composer install which ignores this dependency?

有没有办法做一个忽略这种依赖的作曲家安装?

I think it should be safe, as there are only bug-fixes from 5.5.6 to 5.5.9.

我认为它应该是安全的,因为只有从 5.5.6 到 5.5.9 的错误修复。

采纳答案by Alex

The error message indicates a requirement from the main composer.json. The version requirement can be just adapter:

错误消息表明来自 main 的要求composer.json。版本要求可以只是适配器:

"require": {
    "php": ">=5.5",

After changing the version like this I get:

像这样更改版本后,我得到:

  Problem 1
    - Installation request for classpreloader/classpreloader 2.0.0 -> satisfiable by classpreloader/classpreloader[2.0.0].
    - classpreloader/classpreloader 2.0.0 requires php >=5.5.9 -> your PHP version (5.5.6) or "config.platform.php" value does not satisfy that requirement.
  Problem 2
    - Installation request for laravel/framework v5.1.17 -> satisfiable by laravel/framework[v5.1.17].
    - laravel/framework v5.1.17 requires php >=5.5.9 -> your PHP version (5.5.6) or "config.platform.php" value does not satisfy that requirement.
  Problem 3
    - Installation request for laravelcollective/html v5.1.6 -> satisfiable by laravelcollective/html[v5.1.6].
    - laravelcollective/html v5.1.6 requires php >=5.5.9 -> your PHP version (5.5.6) or "config.platform.php" value does not satisfy that requirement.
  Problem 4
    - laravel/framework v5.1.17 requires php >=5.5.9 -> your PHP version (5.5.6) or "config.platform.php" value does not satisfy that requirement.
    - jenssegers/agent v2.1.7 requires illuminate/support ~4.0|~5.0 -> satisfiable by laravel/framework[v5.1.17].
    - Installation request for jenssegers/agent v2.1.7 -> satisfiable by jenssegers/agent[v2.1.7].

Using the following snippet in composer.json, a php version can be simulated

在 中使用以下代码片段composer.json,可以模拟一个 php 版本

[...]
"config": {
    "preferred-install": "dist",
    "platform": {
        "php": "5.5.9"
    }
}

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

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

platform

Lets you fake platform packages(PHP and extensions) so that you can emulate a production env or define your target platform in the config. Example: {"php": "5.4", "ext-something": "4.0"}.

平台

允许您伪造平台包(PHP 和扩展),以便您可以模拟生产环境或在配置中定义目标平台。示例:{"php": "5.4", "ext-something": "4.0"}。

Don't forget to run a composer.phar updateafter this

不要忘记composer.phar update在此之后运行

回答by Jakub Matczak

You can use --ignore-platform-reqsoption for composer commands like install, updateetc.

您可以使用--ignore-platform-reqs选项像作曲家的命令installupdate等等。

--ignore-platform-reqs: ignore php, hhvm, lib-* and ext-* requirements and force the installation even if the local machine does not fulfill these. See also the platform config option.

--ignore-platform-reqs:忽略php, hhvm, lib-* 和 ext-* 要求并强制安装,即使本地机器不满足这些要求。另请参阅平台配置选项。

https://getcomposer.org/doc/03-cli.md

https://getcomposer.org/doc/03-cli.md

So you can try with

所以你可以尝试

composer install --ignore-platform-reqs

回答by prashant

I got the same issue which resolved with following command :

我遇到了同样的问题,使用以下命令解决了这个问题:

composer config platform.php 7.2.22 

*** you can replace PHP version according to yours.

*** 您可以根据自己的情况更换 PHP 版本。

回答by P.Githinji

running a version independent command solves this error composer install --ignore-platform-reqs

运行与版本无关的命令可解决此错误 composer install --ignore-platform-reqs

回答by Debraj Ghosh

change php version in composer.json

在 composer.json 中更改 php 版本

Delete composer.lock

删除 composer.lock

RUN: composer install

运行:作曲家安装

It works for me

这个对我有用

回答by Faisal Khan

Just add these lines in composer.json file

只需在 composer.json 文件中添加这些行

  "config": {
    "platform": {
      "php": "5.5.9"
    }
  },

Then run command,

然后运行命令,

composer update or install