alpine+nginx+php7的docker环境中的iconv问题

在alpine+nginx+php7的docker环境中,使用函数iconv()

iconv('iso-8859-1', 'utf-8', 'test');

报了如下的错误:

Notice: iconv(): Wrong charset, conversion from `ISO8859-1' to `UTF-8' is not allowed in /var/htdocs/test.php on line 5

解决方法如下:
在Dockerfile中添加如下代码:

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

重新构建镜像即可。

mansoncui
按照你的解决方案,安装gnu-libiconv也添加环境变量,还是不行,能把你的dockerfile贴出来 php —ri iconv iconv iconv support => enabled iconv implementation => unknown iconv library version => unknown Directive => Local Value => Master Value iconv.input_encoding => no value => no value iconv.output_encoding => no value => no value iconv.internal_encoding => no value => no value
回复 · 2个月前

Firefly
RUN apk add --no-cache --repository http://dl-3.alpinelinux.org/alpine/edge/testing gnu-libiconv ENV LD_PRELOAD /usr/lib/preloadable_libiconv.so php 把如上两句加到Dockerfile就可以了
回复 · 2个月前

36nu 分享编程知识及经验

已有账号?立即登录
微信公众号
关注36nu微信公众账号
获取最新编程知识及经验