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 #重啟