ChatGPT解决这个技术问题 Extra ChatGPT

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

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 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 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?

Solution Update

I was missing the php intl extension which provides lib-icu

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:

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 MAMP and 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 version and 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.so to php.ini. In MAMP you can edit php.ini easily by going to File > Edit Template > php.[version].ini

Command Line:

When using Composer or Symfony's Console CLI you'll also need Intl and since the php CLI usually uses a different php.ini you'll want to add the extension directive there too. To find your CLI's php.ini simply do $ php -i |grep php\.ini to discover the file path and add extension=intl.so to that php.ini as well.

To check if Intl is installed you can do $ php -m to check available modules.

which os are you using? then i can provide information on how to update your intl extension.
Don't use pecl/intl as it's for PHP 5.2.x compatibility. As of PHP 5.3, Intl is a core extension.
@JérômeVieilledent it seems the current MAMP distribution doesn't bundle Intl which only leaves you the option to use PECL to build it php.net/manual/en/intl.installation.php

N
Nicolai Fröhlich

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

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

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

( hint: php-cli sometimes uses a different 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 -m from your terminal if the extension has been succesfully enabled.

Check your current intl versions from php with:

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

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

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

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.


Great article. The Composer documentation left me less than certain what if anything the stability flag was coming into play.
I installed php-intl via PEAR/PECL. For some reason INTL::… fails. But, I can see via phpinfo() in the browser that Intl is installed and the ICU version is 49.x. However, Composer still fails with the same error message.
which operating system ? "sudo aptitude install php5-intl" on ubuntu for example. extension enabled in php.ini , visible with php -m from commandline ?
Mac OSX 10.7.5 — when I run php -m I do NOT see intl. I know it works on the webserver, but it's not recognized on the Command Line. So… I have to add it to the Command Line?
I installed via Homebrew, but php -m still does not recognize from CLI?
J
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.

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.

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


Thanks for this. It is absurd that Symfony2 shuts down installation over a feature that should be optional and isn't installed in many environments.
Sorry, but that is not true. Installing symfony 2.3 will introspect the configuration and will determine the correct icu-component. It will NOT shut down.
POC composer.json :"require":{"symfony/symfony": "v2.3.3"}} result: ´Loading composer repositories with package information Installing dependencies (including require-dev) - Installing psr/log (1.0.0) Downloading: 100% - Installing twig/twig (v1.13.2) Downloading: 100% - Installing doctrine/common (2.3.0) Downloading: 100% - Installing symfony/symfony (v2.3.3) Downloading: 100% - Installing symfony/icu (v1.0.0) Downloading: 100% Writing lock file Generating autoload files
As explained in the docs, the problem arises when composer.lock is shared between environments with different versions (or absence) of Intl.
Thanks for this! Crossing my fingers I can get my Symfony2 project running for a client who is on GoDaddy still
t
tweini

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

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

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

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

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.

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

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


l
lenybernard

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

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.

L
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.

Upgrading composer.

php composer.phar self-update

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

extension=php_intl.dll

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

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

And restart apache2 of course. :)

Additional Information:

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

(PHP 5.4)

$ brew install php54-intl

(PHP 5.5)

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

Restart apache.


Looks like this is the Windows fix ;-)
Yes, I'm using windows, however, its not a "windows fix" its a php config and composer update fix. Same steps may need to be taken on a linux or mac box.
Correct. Perhaps you should mention which php/apache distribution you're using then. In your case the intl extension is bundled and just needs to be enabled, that's great news for anyone using the same distro package.
Good point Mark Fox. Here we are for anybody needing it. I'm using the XAMPP stack from apachefriends on a windows 8 box. (version 1.8)
For me this fixed it using XAMPP. The extension was already enabled, but it worked only after adding [intl] intl.default_locale = en_utf8 intl.error_level = E_WARNING
t
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

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

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

"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.

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.


关注公众号,不定期副业成功案例分享
Follow WeChat

Success story sharing

Want to stay one step ahead of the latest teleworks?

Subscribe Now