三、编译安装 PHP 5
3.1、编译安装 LibXML
wget http://xmlsoft.org/sources/libxml2-2.7.8.tar.gz
tar -zxf libxml2-2.7.8.tar.gz
cd libxml2-2.7.8
./configure --prefix=/usr/local
make && make install
3.2、编译安装 Mhash
wget http://nchc.dl.sourceforge.net/project/mhash/mhash/0.9.9.9/mhash-0.9.9.9.tar.bz2
tar -jxf mhash-0.9.9.9.tar.bz2
cd mhash-0.9.9.9/
./configure --prefix=/usr/local
make && make install
3.3、编译安装 LibMcrypt & Mcrypt
wget http://nchc.dl.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 --prefix=/usr/local
make && make install
如果要编译安装 Mcrypt,那么必须先安装 Mhash 和 LibMcrypt,否则会报错。
wget http://nchc.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/
ln -s /usr/local/bin/libmcrypt-config /usr/local/bin
LD_LIBRARY_PATH=/usr/local/lib ./configure --prefix=/usr/local
make && make install
编译安装 Mcrypt,配置时切勿遗漏了在环境变量 LD_LIBRARY_PATH 中指明库的搜索路径 ,或者按一下方法在 /etc/ld.so.conf 动态链接库文件中添加库的搜索路径。(资料1、资料2)。
#编辑,添加共享库路径。
sudo vim /etc/ld.so.conf
添加一行:/usr/local/lib
sudo ldconfig //更新ld.so.cache
3.4、安装编译 Curl
wget http://www.libssh2.org/download/libssh2-1.2.7.tar.gz
tar -zxf libssh2-1.2.7.tar.gz
cd libssh2-1.2.7/
./configure --prefix=/usr/local
make && make install
wget http://curl.haxx.se/download/curl-7.21.2.tar.gz
tar -zxf curl-7.21.2.tar.gz
cd curl-7.21.2/
./configure --prefix=/usr/local --with-ssl=/usr/local/ssl --with-libssh2=/usr/local
make && make install
3.5、编译安装 php5.3.3
wget http://cn.php.net/distributions/php-5.3.3.tar.gz
tar -zxf php-5.3.3.tar.gz
cd php-5.3.3/
./configure --prefix=/usr/local/php --with-apxs2=/usr/local/apache/bin/apxs --with-mysql=/usr/local/mysql --with-mysqli=/usr/local/mysql/bin/mysql_config --with-jpeg-dir=/usr/local --with-png-dir=/usr/local --with-zlib-dir=/usr/local --with-freetype-dir=/usr/local --with-iconv-dir=/usr/local --enable-gd-native-ttf --enable-gd-jis-conv --with-gd=/usr/local --with-libxml-dir=/usr/local --with-mhash=/usr/local --with-mcrypt=/usr/local --with-openssl=/usr/local --with-curl=/usr/local --with-curlwrappers --enable-bcmath --enable-wddx --enable-calendar --enable-mbstring --enable-ftp --enable-zip --enable-sockets
make && make install
四、将Apache与PHP5相结合
cp php.ini-production /usr/local/php/lib/php.ini
vim /usr/local/apache/conf/httpd.conf
4.1、设置php文件后缀
查找"AddType application/x-gzip .gz .tgz",在下面添加:
AddType application/x-httpd-php .php
4.2、设置apache的默认文件名次序
查找"index.html",后面添加“index.php”
index.htm index.html index.php
4.3、开启Apache Rewrite 模块
查找"Options FileInfo" 将"AllowOverride none"
改为 "AllowOverride all" //
4.4、关闭非必须的Apache模块
因为前期我将所有模块都编译了,所以现在要关闭暂不需要的模块以节省资源。必须开启的模块如下:
LoadModule authz_host_module modules/mod_authz_host.so
LoadModule mime_module modules/mod_mime.so
LoadModule autoindex_module modules/mod_autoindex.so
LoadModule dir_module modules/mod_dir.so
LoadModule alias_module modules/mod_alias.so
LoadModule rewrite_module modules/mod_rewrite.so
LoadModule php5_module modules/libphp5.so
4.5、编译安装 ZendOptimizer
官方说明最新版的ZendOptimizer-3.3.9只适用于php5.2,不过你用在php5.3倒也不至于出错。
wget http://downloads.zend.com/optimizer/3.3.9/ZendOptimizer-3.3.9-linux-glibc23-i386.tar.gz
tar -zxf ZendOptimizer-3.3.9-linux-glibc23-i386.tar.gz
cd ZendOptimizer-3.3.9-linux-glibc23-i386/data/5_2_x_comp
cp ZendOptimizer.so /usr/local/lib
vim /usr/local/php/lib/php.ini
[ZendOptimizer]
zend_optimizer.optimization_level=15
zend_extension=/usr/local/lib/ZendOptimizer.so
4.6、重启Apache服务器
httpd -k restart