wodby / php

Generic PHP docker container images
MIT License
152 stars 103 forks source link

Iconv implementation missing #25

Closed alsar closed 6 years ago

alsar commented 6 years ago

The iconv extension is enabled, but there is no implementation available (like glibc). I tried with 7.2, 7.1 and 5.6 images.

The php.ini output:

iconv support => enabled
iconv implementation => unknown
iconv library version => unknown
iconv.input_encoding => no value => no value
iconv.internal_encoding => no value => no value
iconv.output_encoding => no value => no value

As a result the iconv() function fails with translit: iconv('utf-8', 'ascii//TRANSLIT', 'test');

Notice: iconv(): Wrong charset, conversion from 'utf-8' to 'ascii//TRANSLIT' is not allowed

csandanov commented 6 years ago

Thanks for reporting this, the lib was really missing. The implementation and the version will still be missing despite the fix but you can validate that it's working now by running the following snippet in the container as suggested in https://github.com/docker-library/php/issues/240#issuecomment-306246179

php -d error_reporting=22527 -d display_errors=1 -r 'var_dump(iconv("UTF-8", "UTF-8//IGNORE", "This is the Euro symbol '\''€'\''."));'

If it runs without notices it's all good.

alsar commented 6 years ago

It works now. Thank you for the quick fix.

alsar commented 6 years ago

@csandanov The fix works with the CLI but not with FPM.

CLI environment variables from phpinfo():

LD_PRELOAD => /usr/lib/preloadable_libiconv.so php
$_SERVER['LD_PRELOAD'] => /usr/lib/preloadable_libiconv.so php
$_ENV['LD_PRELOAD'] => /usr/lib/preloadable_libiconv.so php

But those variables are missing when I output phpinfo() with FPM.

csandanov commented 6 years ago

Yes, that's because FPM has clear_env = yes by default. Added LD_PRELOAD to the list of env vars that always pass through.

alsar commented 6 years ago

I tried the updated image. The environment variables are now present, but the iconv function with translit still fails with FPM.

csandanov commented 6 years ago

Does it work if you set clear_env = yes and LD_PRELOAD=/usr/lib/preloadable_libiconv.so php-fpm?

alsar commented 6 years ago

No. The change is visible in php.ini, but it still works only for CLI but not FPM.

csandanov commented 6 years ago

Right, we run fpm via sudo. Added LD_PRELOAD directly to the command, my example from above now runs without notices via fpm as well.

alsar commented 6 years ago

It works now. Thanks.

Just a remark. On my local setup the command php -r "var_dump(iconv('UTF-8', 'ASCII//TRANSLIT', 'tést'));" outputs test, but with your image it's t'est. Do you know maybe what is this related to? Locales maybe?

csandanov commented 6 years ago

What's your OS? AFAIK, Linux and Windows use different libs for iconv

alsar commented 6 years ago

I'm on Linux. Ubuntu 16.04 with PHP 7.2.4 with glibc 2.23

csandanov commented 6 years ago

Could be https://github.com/docker-library/php/issues/240#issuecomment-381077806

alsar commented 6 years ago

Probably.

When I output setlocale(LC_ALL, 0); I get: on my local installation: LC_CTYPE=en_US.UTF-8;LC_NUMERIC=C;LC_TIME=C;LC_COLLATE=C;LC_MONETARY=C;LC_MESSAGES=C;LC_PAPER=C;LC_NAME=C;LC_ADDRESS=C;LC_TELEPHONE=C;LC_MEASUREMENT=C;LC_IDENTIFICATION=C

inside the container: C.UTF-8;C;C;C;C;C

csandanov commented 6 years ago

I doubt this issue can be resolved, most likely this caused due to usage of GNU iconv library and not having a good locale support in musl, try using http://php.net/manual/en/transliterator.transliterate.php instead for transliteration:

php -r 'var_dump(transliterator_transliterate("Any-Latin; Latin-ASCII; [\u0080-\u7fff] remove", "A æ Übérmensch på høyeste nivå! И я люблю PHP! есть. fi ¦"));'
gsusI commented 3 years ago

Fixed by installing php7-mbstring php7-iconv in that order

RUN apk --no-cache add php7-mbstring php7-iconv

Original solution here: https://github.com/docker-library/php/issues/240#issuecomment-355489551

csandanov commented 2 years ago

Fixed in the upstream https://github.com/docker-library/php/pull/1264