php 通过 Composer 安装 Symfony 2.3.x 时 lib-icu 依赖的问题

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/16753105/
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 11:39:02  来源:igfitidea点击:

Problems with lib-icu dependency when installing Symfony 2.3.x via Composer

phpsymfonycomposer-php

提问by Mark Fox

I've had no problems installing Symfony 2.2.x using Composer, I've always just copied the stable version at http://symfony.com/download.

我使用 Composer 安装 Symfony 2.2.x 没有任何问题,我总是在http://symfony.com/download复制稳定版本。

composer create-project symfony/framework-standard-edition myproject/ 2.2.1

(I have Composer installed globally)
Curious about 2.3.0-RC1 I figured this would go smoothly:

(我在全球安装了 Composer)
对 2.3.0-RC1 感到好奇我认为这会顺利进行:

composer create-project symfony/framework-standard-edition mynewerproject/ 2.3.0-RC1

But got shutdown by the following errors:

但是由于以下错误而关闭:

Your requirements could not be resolved to an installable set of packages.

Problem 1
    - symfony/icu v1.2.0-RC1 requires lib-icu >=4.4 -> the requested linked library icu has the wrong version installed or is missing from your system, make sure to have the extension providing it.
    - symfony/icu v1.1.0-RC1 requires lib-icu >=3.8 -> the requested linked library icu has the wrong version installed or is missing from your system, make sure to have the extension providing it.
    - symfony/symfony v2.3.0-RC1 requires symfony/icu >=1.0,<2.0 -> satisfiable by symfony/icu[v1.1.0-RC1, v1.2.0-RC1].
    - Installation request for symfony/symfony 2.3.* -> satisfiable by symfony/symfony[v2.3.0-RC1].

Do I need to tweak the composer.json file?

我需要调整 composer.json 文件吗?



Solution Update

解决方案更新

I was missing the php intl extensionwhich provides lib-icu

我错过了提供lib-icuphp intl 扩展

So easy, install and configure the intl extension. As of PHP 5.3 the Intl extension is distributed by default, but some distributions, like MAMP, don't have Intl so you'll need to acquire it. I used PEAR:

如此简单,安装和配置 intl 扩展。从 PHP 5.3 开始,默认情况下分发 Intl 扩展,但某些分发,如 MAMP,没有 Intl,因此您需要获取它。我用过

My steps:

我的步骤:

  • Install the Intl extension (maintained by PECL): $ pear install pecl/intl— you may have to add the pecl channel to pear first.
  • If you use MAMPand have never worked with pear/pecl check lullabot's helpful blog post; MAMP doesn't ship with the php source, so you have to download the source for your php versionand move the source into /Applications/MAMP/bin/php/php[version]/include/php(as covered in the blog post)
  • PEAR couldn't find my php.ini, so I had to manually add extension=intl.soto php.ini. In MAMP you can edit php.ini easily by going to File > Edit Template > php.[version].ini
  • 安装 Intl 扩展(由 PECL 维护):$ pear install pecl/intl— 您可能必须先将 pecl 通道添加到 pear。
  • 如果您使用 MAMP并且从未使用过 pear/pecl,请查看lullabot 的有用博客文章;MAMP 不附带 php 源,因此您必须下载 php 版本的源并将源移动到/Applications/MAMP/bin/php/php[version]/include/php(如博客文章中所述)
  • PEAR 找不到我的 php.ini,所以我不得不手动添加extension=intl.so到 php.ini。在 MAMP 中,您可以通过转到 File > Edit Template > php.[version].ini 轻松编辑 php.ini

Command Line:

命令行:

  • When using Composer or Symfony's Console CLI you'll also need Intl and since the phpCLI usually uses a different php.iniyou'll want to add the extension directive there too. To find your CLI's php.ini simply do $ php -i |grep php\.inito discover the file path and add extension=intl.soto that php.ini as well.
  • To check if Intl is installed you can do $ php -mto check available modules.
  • 当使用 Composer 或 Symfony 的控制台 CLI 时,您还需要 Intl,并且由于phpCLI 通常使用不同的,php.ini您也需要在那里添加扩展指令。要找到您的 CLI 的 php.ini,只需$ php -i |grep php\.ini找到文件路径并将其添加extension=intl.so到该 php.ini 中即可。
  • 要检查是否安装了 Intl,您可以$ php -m检查可用模块。

回答by Nicolai Fr?hlich

update your php-intlextension, that's where the icu error comes from!

更新您的php-intl扩展,这就是 icu 错误的来源!

sudo aptitude install php5-intl                 // i.e. ubuntu
brew install icu4c                              // osx

check the extension is enabled and properly configured in php.ini aswell.

检查扩展是否已启用并在 php.ini 中正确配置。

( hint: php-cli sometimes uses a different php.ini )

(提示:php-cli 有时使用不同的 php.ini )

php.ini

配置文件

extension=intl.so       ; *nix
extension=php_intl.dll  ; windows

[intl]
intl.default_locale = en_utf8
intl.error_level = E_WARNING

check your phpinfo()AND php -mfrom your terminal if the extension has been succesfully enabled.

如果扩展已成功启用phpinfo(),请php -m从您的终端检查您的AND 。

Check your current intl versions from php with:

从 php 中检查您当前的国际版本:

Intl::getIcuVersion();
Intl::getIcuDataVersion();


attention: not needed anymore( symfony 2.3 has meanwhile been released)

注意:不再需要symfony 2.3 同时发布

add the minimum stability flag @dev or @rc to your dependency like this please:

请像这样将最低稳定性标志 @dev 或 @rc 添加到您的依赖项中:

composer create-project symfony/framework-standard-edition mynewerproject/ 2.3.*@dev 

The default stability in composer is stable which symfony 2.3 branch is not currently ( it's @rc ). Read more an stability flags here.

composer 中的默认稳定性是稳定的,symfony 2.3 分支当前不是(它是 @rc )。在此处阅读更多稳定性标志。

回答by John Kary

Many applications will only be supporting "en" locale and will have no need for translation capabilities or php-intl. If this is you, or you can't install php-intl on your server, you can explicitly add symfony/icu~1.0 to your composer.json. 1.0 does not require php-intl, whereas 1.1+ does.

许多应用程序只支持“en”语言环境,不需要翻译功能或 php-intl。如果这是您,或者您无法在您的服务器上安装 php-intl,您可以明确地将symfony/icu~1.0添加到您的composer.json. 1.0 不需要 php-intl,而 1.1+ 需要。

If you don't need translation features:

如果您不需要翻译功能:

$ php bin/composer.phar require symfony/icu ~1.0

Without this declaration and trying to install symfony/symfony 2.3 Composer may try to install symfony/icu ~1.2 which would require you to install php-intl.

如果没有这个声明并尝试安装 symfony/symfony 2.3 Composer 可能会尝试安装 symfony/icu ~1.2 这将需要您安装 php-intl。

This is explicitly covered more extensively in the Symfony Intl Component's docsunder "ICU and Deployment Problems".

这在“ICU 和部署问题”下的Symfony Intl 组件文档中有更广泛的明确介绍。

回答by tweini

A solution regarding this or similar problems can be found here: ICU and Deployment Problems

可以在此处找到有关此问题或类似问题的解决方案:ICU 和部署问题

The behavior of composer should be intelligent selecting the right icu-component:

composer 的行为应该是智能选择正确的 icu 组件:

  • symfony/icu 1.0.*: when the intl extension is not available
  • symfony/icu 1.1.*: when intl is compiled with ICU 4.0 or higher
  • symfony/icu 1.2.*: when intl is compiled with ICU 4.4 or higher
  • symfony/icu 1.0.*: 当 intl 扩展不可用时
  • symfony/icu 1.1.*: 当 intl 用 ICU 4.0 或更高版本编译时
  • symfony/icu 1.2.*: 当 intl 用 ICU 4.4 或更高版本编译时

There should be (theoretically) no error installing symfony 2.3. with no intl-extension.

安装 symfony 2.3 应该(理论上)没有错误。没有国际扩展。

But you can be trapped when your development-environment differs from your production-server like mentioned in this article:

但是,当您的开发环境与本文中提到的生产服务器不同时,您可能会陷入困境:

  • the development machines are compiled with ICU 4.4 or higher, but the server is compiled >with a lower ICU version than 4.4
  • the intl extension is available on the development machines but not on the server.
  • 开发机器用ICU 4.4或更高版本编译,但服务器编译> ICU版本低于4.4
  • intl 扩展在开发机器上可用,但在服务器上不可用。

When you have no root-access to your production-server you can fix it as mentioned in this article. (tweaking composer.json)

当您没有对生产服务器的 root 访问权限时,您可以按照本文所述进行修复。(调整 composer.json)

Hope this additional information helped as it helped me for this special case with different environments.

希望这些附加信息对我有所帮助,因为它对我在不同环境下的这种特殊情况有所帮助。

回答by lenybernard

Mac OS Mavericks comes with PHP 5.4.17 without intl. To get this, you'll have to follow those steps :

Mac OS Mavericks 附带 PHP 5.4.17,没有 intl。要获得此功能,您必须按照以下步骤操作:

brew install icu4c
sudo pecl install intl 
The path to the ICU libraries and headers is: /usr/local/opt/icu4c/
Edit /etc/php.ini and add extension=intl.so to the end.

回答by Layton Everson

I know that this answer may not be the correct answer to this person's problem, but it was the solution to my problem with the same title. I was able to fix this problem for myself by enabling the intl extension in php.ini and upgrading composer.

我知道这个答案可能不是这个人问题的正确答案,但它是我同名问题的解决方案。通过在 php.ini 中启用 intl 扩展并升级 composer,我能够为自己解决这个问题。

Upgrading composer.

升级作曲家。

php composer.phar self-update

Remove comment from this line (in php.ini):

从这一行中删除注释(在 php.ini 中):

extension=php_intl.dll

And also remove comment the these two lines below [intl] in (php.ini):

并删除 (php.ini) 中 [intl] 下面这两行的注释:

[intl]
intl.default_locale = en_utf8
intl.error_level = E_WARNING

And restart apache2 of course. :)

当然重启apache2。:)

Additional Information:

附加信息:

If your using mac and installed php with Homebrew follow these steps:

如果您使用 mac 并使用 Homebrew 安装了 php,请按照以下步骤操作:

(PHP 5.4)

(PHP 5.4)

$ brew install php54-intl

(PHP 5.5)

(PHP 5.5)

$ brew tap josegonzalez/php
$ brew tap homebrew/dupes
$ brew install josegonzalez/php/php55-intl
$ sudo apachectl restart

Restart apache.

重启阿帕奇。

回答by thewbb

A better solution is to fix your composer.json to the version required by the production server. First, determine the ICU version on the server: 1 2

更好的解决方案是将您的 composer.json 修复为生产服务器所需的版本。首先确定服务器上的ICU版本:1 2

$ php -i | grep ICU
ICU version => 4.2.1

Then fix the Icu component in your composer.json file to a matching version:

然后将 composer.json 文件中的 Icu 组件修复为匹配的版本:

"require: {
    "symfony/icu": "1.1.*"
}

Set the version to "1.0." if the server does not have the intl extension installed; "1.1." if the server is compiled with ICU 4.2 or lower.

如果服务器没有安装 intl 扩展,则将版本设置为“1.0. ”;“1.1.”如果服务器是用ICU 4.2或更低版本编译的。

Finally, run

最后,运行

php composer.phar update symfony/icu

on your development machine, test extensively and deploy again. The installation of the dependencies will now succeed.

在您的开发机器上,广泛测试并再次部署。依赖项的安装现在将成功。