ibiconv 元件安装好了可以让我们 php 支援 iconv 函式了,这个函式的作用就是字元编码强制转换了,下面和 111cn 小编一起来看一个 Linux 中安装 libiconv 使 php 支援 iconv 函式的例子吧。
问题:
线上执行的 lamp 站群服务器,php 不支援 iconv 函式。
解决方法:
安装 libiconv,重新编译 apache,使 php 支援 iconv 函式,实现 utf-8 和 gb2312 编码的转换。
具体步骤:
1 、下载 libiconv
cd /usr/local/src
wget http://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.14.tar.gz #下载
2 、安装 libiconv
cd /usr/local/src
tar zxvf libiconv-1.14.tar.gz #解压
cd libiconv-1.14 #进入安装目录
./configure –prefix=/usr/local/libiconv #配置
make #编译
make install #安装
3 、重新编译 php
查询系统之前的 php 编译引数
cd /usr/local/php/bin #进入 php 安装目录
./php -i |more #检视 php 编译引数
如下:
‘–with-pdo_sqlite=shared’ ‘–enable-bcmath=shared’ ‘–enable-ftp=shared’ ‘–enable-mbstring=shared’ ‘–with-iconv=shared’ ‘–enable-sockets=shared’ ‘–enable-zip’ ‘–enable-soap=s
hared’ ‘–with-openssl’ ‘–with-zlib’ ‘–with-curl=shared’ ‘–with-gd=shared’ ‘–with-jpeg-dir’ ‘–with-png-dir’ ‘–with-freetype-dir’ ‘–with-mcrypt=shared’ ‘–with-mhash=shared’ ‘–with-mysql=/ho
me/server/mysql’ ‘–with-mysqli=/home/server/mysql/bin/mysql_config’ ‘–with-pdo-mysql=/home/server/mysql/bin/mysql_config’ ‘–without-pear’ ‘–with-libdir=lib64’
对引数进行修改:
如下
./configure –prefix=/usr/local/php –with-config-file-path=/usr/local/php/etc –with-apxs2=/usr/local/apache/bin/apxs –with-gettext=shared –with-sqlite=shared –with-pdo_sqlite=shared –enable-bcmath=shared –enable-ftp=shared –enable-mbstring=shared –with-iconv-dir=/usr/local/libiconv –enable-sockets=shared –enable-zip –enable-soap=shared –with-openssl –with-zlib –with-curl=shared –with-gd=shared –with-jpeg-dir –with-png-dir –with-freetype-dir –with-mcrypt=shared –with-mhash=shared –with-mysql=/home/server/mysql –with-mysqli=/home/server/mysql/bin/mysql_config –with-pdo-mysql=/home/server/mysql/bin/mysql_config –without-pear –with-libdir=lib64
备注:修改部分
取消原来的–with-iconv=shared
替换为:–with-iconv-dir=/usr/local/libiconv
取消引数两边的单引号
其它不变
cd /usr/local/src/php #进入 php 安装包目录(注意 php 版本要和之前一样)
./configure –prefix=/usr/local/php –with-config-file-path=/usr/local/php/etc –with-apxs2=/usr/local/apache/bin/apxs –with-gettext=shared –with-sqlite=shared –with-pdo_sqlite=shared –enable-bcmath=shared –enable-ftp=shared –enable-mbstring=shared –with-iconv-dir=/usr/local/libiconv –enable-sockets=shared –enable-zip –enable-soap=shared –with-openssl –with-zlib –with-curl=shared –with-gd=shared –with-jpeg-dir –with-png-dir –with-freetype-dir –with-mcrypt=shared –with-mhash=shared –with-mysql=/home/server/mysql –with-mysqli=/home/server/mysql/bin/mysql_config –with-pdo-mysql=/home/server/mysql/bin/mysql_config –without-pear –with-libdir=lib64 #配置
make #编译
make install #安装
4 、重启 apache 使设定生效
service httpd restart #重启