今天小编要为大家带来的是CentOS下libiconv库的安装和使用介绍!希望对大家会有帮助!有需要的朋友一起去看看吧
Linux下安装libiconv使php支持iconv函数
libiconv组件安装好了可以让我们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.15.tar.gz #下载
2、安装libiconv
cd /usr/local/src
tar zxvf libiconv-1.15.tar.gz #解压
cd libiconv-1.15 #进入安装目录
./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 #重启
故障解决!
Linux下libiconv库的安装和使用:
1.编译安装libiconv库
包的下载页面http://www.gnu.org/software/libiconv/
$ ./configure –prefix=/usr/local
$ make
$ make install
2.在/usr/local/lib/目录下拷备需要的库文件libcharset.so.1, libiconv.so.2。
评论前必须登录!
注册