④安装libmcrypt库(libmcrypt是加密算法扩展库。支持DES, 3DES, RIJNDAEL, Twofish, IDEA, GOST, CAST-256, ARCFOUR, SERPENT, SAFER+等算法)
解压:tar -zxvf libmcrypt-version.tar.gz
进入:cd libmcrypt-version
预编译:./configure --prefix=/usr/local/libmcrypt
编译安装:make && make install
⑤安装mhash库()
解压:tar -zxvf mhash-0.9.9.9.tar.gz
进入:cd mhash-version
预编译:./configure --prefix=/usr/local/mhash
编译安装: make && make install
⑥安装mcrypt库。在这里,我们需要先安装libmcrypt和mhash。这是因为安装mcrypty需要这两个库的支持。
解压:tar -zxvf mcrypt-2.6.8.tar.gz
进入:cd mcrypt-version
设置mcrypt安装过程中对libmcrypt和mhash的依赖:
export LD_LIBRARY_PATH=/usr/local/libmcrypt/lib/:/usr/local/mhash/lib:$LD_LIBRARY_PATH
export LDFLAGS="-L/usr/local/mhash/lib/ -I/usr/local/mhash/lib"
export CFLAGS="-I/usr/local/mhash/include/"
预编译:./configure --prefix=/usr/local/mcrypt --with-libmcrypt-prefix=/usr/local/libmcrypt
编译安装:make && make install。
三、安装php
①php安装
下载php-5.3.*.tar.gz版本的php。在php-5.3.*以后的版本中,已经自带了php-fpm管理了。不需要在给php安装php-fpm的补丁了。
解压:tar -zxvf php-5.3.*.tar.gz;
预编译:./configure --prefix=/usr/local/php --with-mysql=/usr/local/mysql/ --with-jpeg-dir=/usr/local/jpeg/ --with-freetype-dir=/usr/local/freetype/ --enable-gd-native-ttf --with-png-dir=/usr/local/libpng --enable-soap --enable-sockets --with-curl=/usr/local/curl/ --with-libxml-dir=/usr/local/libxml2/ --with-zlib=/usr/local/zlib/ --enable-mbstring --enable-zip --enable-fpm --disable-debug --with-iconv-dir=/usr/local/libiconv/ --with-gd=/usr/local/gd/ --with-mcrypt=/usr/local/libmcrypt/ --with-openssl=/usr/local/openssl/ --with-mhash=/usr/local/mhash/
编译安装:make && make install。
②安装完成后设置
由于php5.3内置了fastcgi的支持,即php-fpm。所以配置一下就可以应用php-fpm工具管理fastcgi了。
生成配置文件:cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf(即将php安装到的目录中的etc下的php-fpm.conf.default复制一份并重命名为php-fpm.conf)
打开配置文件中的下面几行注释(php-fpm.conf):
pid = run/php-fpm.pid
pm.start_servers = 20
pm.min_spare_servers = 5
pm.max_spare_servers = 35
完成上面操作后,就可以启动php-fpm了:/usr/local/php/sbin/php-fpm start(stop|restart);
四、设置php-fpm服务每次开机启动项
cp $PHP_SOURCE_DIR/sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm ($PHP_SOURCE_DIR--php的安装目录)
chmod 700 /etc/init.d/php-fpm
chkconfig --add php-fpm
chkconfig --level 36 php-fpm on
服务方式启动php-fpm
service php-fpm restart
五、安装php的扩展工具
①安装ZendGuardLoader(从php5.2以后zend optimizer就改名为ZendGuardLoader)
解压:tar -zxvf ZendGuardLoader-php-5.3-linux-glibc23-i386.tar.gz;
创建文件夹:mkdir -p /usr/local/Zend/lib;
复制ZendGuardLoader.so:cp ZendGuardLoader.so /usr/local/Zend/lib/
在php.ini中添加ZendGuardLoader的扩展信息:
[Zend Guard]
zend_extension=/usr/local/zend/ZendGuardLoader.so
zend_loader.enable=1
zend_loader.disable_licensing=0
zend_loader.obfuscation_level_support=3
zend_loader.license_path=
重启php-fpm:service php-fpm restart;
注意:在重启php-fpm时有可能遇到以下问题: cannot restore segment prot after reloc: Permission denied。
遇到以上问题后,不要着急,这是SELinux限制导致的。我们可以先看看当前SELinux的限制状态:getenforce
如果是强制状态,在这个时候,最简单的方式是关闭强制状态:setenforce 0;有可能带来安装问题。
但这是就可以正常加载ZendGuardLoader了。成功后,查看phpinfo()。有如下信息
②php加速器eaccelerator:
解压:tar jxvf eaccelerator-0.9.6.1.tar.bz2
进入:cd eaccelerator-0.9.6.1
安装php外挂模块:/usr/local/php/bin/phpize
预编译:./configure --enable-eaccelerator=shared --with-php-config=/usr/local/php/bin/php-config
编译安装:make && make install
配置eAccelerator加速PHP:mkdir -p /usr/local/php/eaccelerator_cache
编辑php.ini文件:
[eaccelerator]
zend_extension="/usr/local/php52/lib/php/extensions/no-debug-non-zts-20060613/eaccelerator.so"
eaccelerator.shm_size="64"
eaccelerator.cache_dir="/usr/local/php52/eaccelerator_cache"
eaccelerator.enable="1"
eaccelerator.optimizer="1"
eaccelerator.check_mtime="1"
eaccelerator.debug="0"
eaccelerator.filter=""
eaccelerator.shm_max="0"
eaccelerator.shm_ttl="3600"
eaccelerator.shm_prune_period="3600"
eaccelerator.shm_only="0"
eaccelerator.compress="1"
eaccelerator.compress_level="9"
保存然后重启php-fpm:service php-fpm restart。
注意:1、
编译gd-2.0.35.tar.gz时报错:
gcc -DHAVE_CONFIG_H -I. -I. -I. -I/usr/local/freetype/include/freetype2 -I/usr/local/freetype/include -I/usr/local/freetype/include -I/usr/local/jpeg/include -g -O2 -MT gd_png.lo -MD -MP -MF .deps/gd_png.Tpo -c gd_png.c -fPIC -DPIC -o .libs/gd_png.o
gd_png.c:16:53: error: png.h: No such file or directory
gd_png.c:47: error: expected specifier-qualifier-list before 'jmp_buf'
gd_png.c:54: error: expected ')' before 'png_ptr'
gd_png.c:82: error: expected ')' before 'png_ptr'
gd_png.c:92: error: expected ')' before 'png_ptr'
解决办法:#vi gd_png.c
将:(#include "png.h" /* includes zlib.h and setjmp.h */)
替换成:(#include "/usr/local/libpng/include/png.h" /* includes zlib.h and setjmp.h */)
然后再make就可以了