問題:
線上運行的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 #重啟
故障解決!