CentOS 6.5 64位VPS源码安装PHP 5.2.17

CentOS 6.5 64位VPS源码安装PHP 5.2.17
先添加用户及用户组

/usr/sbin/groupadd www
/usr/sbin/useradd -g www www

一、编译安装PHP 5.2.17 所需的支持库
PS, 如果已经安装过这些支持库的,不必重复安装!
按顺序依次安装如下软件:

1.1 下载LIBICONV 1.14 并安装
Libiconv URL: http://www.gnu.org/software/libiconv/ http://ftp.gnu.org/pub/gnu/libiconv/

wget http://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.14.tar.gz
tar zxvf libiconv-1.14.tar.gz && cd libiconv-1.14
./configure --prefix=/usr/local/libiconv --enable-extra-encodings && make && make install && cd ../

注:enable-extra-encodings 选项是为了能支持以下扩展字符集,详情请参考:http://www.gnu.org/software/libiconv/
主要是为了支持Magento的 ISO-2022-JP Mail for Japanese
插件所需要的 ISO-2022-JP-3 字符集

European languages
CP{437,737,775,852,853,855,857,858,860,861,863,865,869,1125}
Semitic languages
CP864
Japanese
EUC-JISX0213, Shift_JISX0213, ISO-2022-JP-3
Chinese
BIG5-2003 (experimental)
Turkmen
TDS565
Platform specifics
ATARIST, RISCOS-LATIN1

1.2, 下载 MHASH 0.9.9.9 并安装
URl: http://sourceforge.net/projects/mhash/

wget http://downloads.sourceforge.net/project/mhash/mhash/0.9.9.9/mhash-0.9.9.9.tar.bz2 
tar jxvf mhash-0.9.9.9.tar.bz2 && cd mhash-0.9.9.9
./configure && make && make install && cd ../
/sbin/ldconfig

1.3,下载 MCRYPT 2.6.8 并安装
myrypt URL: http://sourceforge.net/projects/mcrypt/?source=dlpaz

wget http://hivelocity.dl.sourceforge.net/project/mcrypt/MCrypt/2.6.8/mcrypt-2.6.8.tar.gz
tar zxf mcrypt-2.6.8.tar.gz && cd mcrypt-2.6.8
./configure && make && make install
/sbin/ldconfig
cd ../

1.4, 下载 LIBMCRYPT 2.5.8 并安装
URL: http://sourceforge.net/projects/mcrypt/files/Libmcrypt/

wget http://downloads.sourceforge.net/project/mcrypt/Libmcrypt/2.5.8/libmcrypt-2.5.8.tar.gz
tar zxf libmcrypt-2.5.8.tar.gz && cd libmcrypt-2.5.8
./configure && make && make install
/sbin/ldconfig
cd libltdl/
./configure --enable-ltdl-install && make && make install
cd ../../

创建系统软连接

ln -s /usr/local/lib/libmcrypt.* /usr/lib/
ln -s /usr/local/bin/libmcrypt-config /usr/bin/libmcrypt-config
ln -s /usr/local/lib/libmhash.* /usr/lib/

开始以下步骤前,请确保已经成功安装MySQL 或者 MySQL的变种如:mariadb,PHP 5.2.17 如果没有安装MySQL 是无法顺利安装的,否则安装后无法支持 MySQL,需要重新编译!

二、下载、编译、安装PHP 5.2.17
第一步,下载、编译、安装PHP 5.2.17源码
注意下文中 –with-mysql –with-mysqli 字段的路径根据自己服务器上MySQL的实际情况更改

wget http://museum.php.net/php5/php-5.2.17.tar.gz
#下载PHP 的 php-fpm 补丁
wget http://php-fpm.org/downloads/php-5.2.17-fpm-0.5.14.diff.gz
tar zxvf php-5.2.17.tar.gz
#应用php-fpm 补丁
gzip -cd php-5.2.17-fpm-0.5.14.diff.gz | patch -d php-5.2.17 -p1

#请注意一下编译参数中的 --with-mysql --with-mysqli 及 --with-iconv 参数的路径,改为你服务器中实际项目地址

./configure --prefix=/usr/local/php \
--enable-fastcgi \
--enable-fpm \
--with-config-file-path=/usr/local/php/etc \
--with-mysql=/usr/local/mariadb \
--with-mysqli=/usr/local/mariadb/bin/mysql_config \
--with-iconv-dir=/usr/local \
--with-freetype-dir \
--with-jpeg-dir \
--with-png-dir \
--with-gd \
--enable-gd-native-ttf \
--with-zlib \
--enable-zip \
--with-libxml-dir=/usr \
--enable-xml \
--disable-rpath \
--enable-discard-path \
--enable-safe-mode \
--enable-bcmath \
--enable-shmop \
--enable-sysvsem \
--enable-inline-optimization \
--with-curl \
--with-curlwrappers \
--enable-mbregex \
--enable-force-cgi-redirect \
--enable-mbstring \
--with-mcrypt \
--with-iconv=/usr/local/libiconv \
--with-openssl \
--with-mhash \
--enable-pcntl \
--enable-sockets \
--with-ldap \
--with-ldap-sasl \
--with-xmlrpc \
--enable-soap

make ZEND_EXTRA_LIBS='-liconv'
make install

第二步:下载安装 PDO_MYSQL

wget http://pecl.php.net/get/PDO_MYSQL-1.0.2.tgz

tar zxvf PDO_MYSQL-1.0.2.tgz && cd PDO_MYSQL-1.0.2/
/usr/local/php/bin/phpize
./configure --with-php-config=/usr/local/php/bin/php-config --with-pdo-mysql=/usr/local/mariadb

第三步:安装ZendOptimizer-3.3.9(可选)
ZendOptimizer的作用是分析,优化由Zend 编译器加密产生的代码的程序,对不是Zend编译器加密过的程序,没有必要安装这个。
64位:http://downloads.zend.com/optimizer/3.3.9/ZendOptimizer-3.3.9-linux-glibc23-x86_64.tar.gz
32位:http://downloads.zend.com/optimizer/3.3.9/ZendOptimizer-3.3.9-linux-glibc23-i386.tar.gz

cd /soft
http://downloads.zend.com/optimizer/3.3.9/ZendOptimizer-3.3.9-linux-glibc23-x86_64.tar.gz
tar xzf ZendOptimizer-3.3.9-linux-glibc23-x86_64.tar.gz
cd ZendOptimizer-3.3.9-linux-glibc23-x86_64/data/5_2_x_comp/
mkdir -p /usr/local/zend/lib/
cp ZendOptimizer.so /usr/local/zend/lib

加载zendoptimizer,打开/usr/local/php/etc/php.ini文件,在配置文件的最底部加入如下代码:

[zend]
zend_optimizer.optimization_level=15
zend_extension=/usr/local/Zend/lib/ZendOptimizer.so

遇到一些问题的解决办法:
1, configure: error: Cannot find ldap libraries in /usr/lib 解决办法

今天在centos 6.2 64位版本上安装LNMP,config php的时候出现下面错误而退出
configure: error: Cannot find ldap libraries in /usr/lib
解决办法:

cp -frp /usr/lib64/libldap* /usr/lib/

然后再./configure …即可

2, configure: error: libpng.(a|so) not found, libjpeg.(a|so)not found 的解决办法
http://blog.csdn.net/alexdream/article/details/7408438

解决configure: error: libpng.(a|so) not found. libjpeg.(a|so)not found

yum install libpng libpng-devel libjpeg libjpeg-deve

# ln -s /usr/lib64/libjpeg.so /usr/lib/
# ln -s /usr/lib64/libpng.so /usr/lib/