Php: iconv on Alpine 3.13

Created on 19 Jan 2021  路  7Comments  路  Source: docker-library/php

Using the PHP alpine images, this code...:

<?php
ini_set('display_errors', '1');
error_reporting(-1);
iconv("UTF-8", "ASCII//TRANSLIT", "foobar");

...causes this error:

iconv(): Wrong charset, conversion from `UTF-8' to `ASCII//TRANSLIT' is not allowed in [...]

This is a long-known issue, however the situation has changed significantly so I think a new issue is appropriate.

Until now the problem was commonly solved by this workaround:

RUN apk add --no-cache --repository http://dl-cdn.alpinelinux.org/alpine/edge/community/ gnu-libiconv
ENV LD_PRELOAD /usr/lib/preloadable_libiconv.so

This however no longer works with gnu-libiconv 1.16-r0 because the preloadable_libiconv.so has been removed (see alpine aports issue and related libiconv commit).

On Alpine 3.12 we can use gnu-libiconv=1.15-r2.

On Alpine 3.13 however the version no longer exists and consequently the workaround is not available.

EDIT: My bad. The version is available in 3.13, just missing in edge.

Is there any other way to fix this? Perhaps somehow using --with-iconv when building PHP? (Not sure, just an idea.)

Most helpful comment

To anyone visiting this issue, the current workaround is

-apk add gnu-libiconv
+apk add gnu-libiconv=1.15-r2

All 7 comments

RUN apk add --no-cache  gnu-libiconv
ENV LD_PRELOAD /usr/lib/preloadable_libiconv.so

Ah okay so it only doesn't work with edge for now but v3.13 will be fine. Good to know but still it means that the current workaround might not work later.

To anyone visiting this issue, the current workaround is

-apk add gnu-libiconv
+apk add gnu-libiconv=1.15-r2

I looked at the documentation , used 3.12 is good. thanks~

FROM alpine:3.12
RUN     apk update && \
        apk add php7=7.3.27-r0 php7-iconv 
        .............................       
#fix apline-php7-iconv
RUN apk add --no-cache --repository http://dl-cdn.alpinelinux.org/alpine/edge/community/ gnu-libiconv=1.15-r2
ENV LD_PRELOAD /usr/lib/preloadable_libiconv.so php
cmd["php"]

my current workaround is the stick with alpine3.13 and gnu-libiconv=1.15-r3

my current workaround is the stick with alpine3.13 and gnu-libiconv=1.15-r3

For easy copy&pasting:

RUN apk add --no-cache --repository http://dl-cdn.alpinelinux.org/alpine/v3.13/community/ gnu-libiconv=1.15-r3

ENV LD_PRELOAD /usr/lib/preloadable_libiconv.so php
Was this page helpful?
0 / 5 - 0 ratings