LNMP架构php升级问题及解决方法 php-5.3.10升级到php-5.4.0

公司有台内网测试机环境为LNMP(开发的哥们搭建的)。它的安装步骤及方法大致跟张宴

( http://blog.s135.com/nginx_php_v6/)  写的差不多。现在呢….有这样一个需求,公司的开发工程师想要单独升级PHP版本来做一些功能性测试,于是总监要求我来完成此需求!单独看就升级PHP一个程序,貌似很简单,但是在这个升级过程当中,遇到了许多问题,并把它列出来,并写出解决办法!!!!
机器为X86_64  软件版本为:Linux(Centos5.7)+Nginx(1.0.12)+Mysql+PHP(5.3.10 php-fpm模式)
欲升级为PHP-5.4.0 升级后出现问题的原因大都是以下软件版本不搭配引起的,对php-5.4.0的支持问题。
没升级前的版本为:memcache-2.2.6.tgz   eaccelerator-0.9.6.1.tar.bz2   imagick-3.0.1.tgz
编译安装新版本时,如果不知道以前的编译参数可以使用: php –i查看,新编译时,尽量跟以前一样。
 
 
  1. tar xvzf php-5.4.0.tar.gz  
  2. cd php-5.4.0  
  3. ./configure --prefix=/usr/local/php-5.4.0 --with-config-file-path=/usr/local/php-5.4.0/etc --with-mysql=/usr/local/mysql --with-pdo-mysql=/usr/local/mysql --with-ldap --enable-sockets --with-mysqli=/usr/local/mysql/bin/mysql_config --with-iconv-dir=/usr/local --enable-soap --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr --enable-xml --disable-rpath --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --with-curl --with-curlwrappers --enable-mbregex --enable-fpm --enable-mbstring --with-mcrypt --with-gd --enable-gd-native-ttf --with-openssl --enable-pcntl --with-mhash --with-xmlrpc --with-ldap-sasl--enable-zip  
  4. make ZEND_EXTRA_LIBS='-liconv' 
  5. make install  
  6. cp php.ini-production /usr/local/php-5.4.0/etc/php.ini  

 (#注:之前php-5.3.10编译时加了--enable-safe-mode选项,但是这个选项没必要,且会带来许多的麻烦,详解可以google一下,php-5.4.0已经去掉了该选项,编译时可以 ./configure --help | grep “safe-mode” 查看一下,没有信息输出,表示已经不支持!)

编译时,如果加了--enable-safe-mode,将会有以下输出:
configure: WARNING: unrecognized options: --enable-safe-mode
 如果还有问题,如下列信息:
PEAR package PHP_Archive not installed: generated phar will require PHP's phar extension be enabled.
这说明没有安装PEAR,解决方案有两种:
./configure时附加--without-pear
2、从http://pear.php.net/go-pear下列未打包的pear安装包并执行,步骤如下:
# wget http://pear.php.net/go-pear.phar
# /usr/local/php-5.3.10/bin/php go-pear.phar
为网上的解决办法,我没有安装,请自己甄别!!!!!!!
编译安装PHP5扩展模块:
 imagick   memcache   eaccelerator   ImageMagick 
 
 
  1. tar xvzf imagick-3.1.0RC1.tgz  #(最新测试版本,此时还没有比3.0.1更高的正式版)  
  2. cd imagick-3.1.0RC1/  
  3. /usr/local/php-5.4.0/bin/phpize  
  4. ./configure --with-php-config=/usr/local/php-5.4.0/bin/php-config  
  5. make  
  6. make install  

 (#注:之前的版本为:imagick-3.0.1.tgz,之所以不用此版本或者更低的版本,是因为此版本编译的时候无法通过,有大量的报错信息,换成3.1的测试版没问题:

/usr/local/src/nginx/soft/imagick-3.0.1/imagick_class.c:9534: error: ‘struct _php_core_globals’ has no member named ‘safe_mode’
/usr/local/src/nginx/soft/imagick-3.0.1/imagick_class.c:9534: error:
‘CHECKUID_CHECK_FILE_AND_DIR’ undeclared (first use in this function)
/usr/local/src/nginx/soft/imagick-3.0.1/imagick_class.c:9534: error: (Each undeclared identifier is reported only once
/usr/local/src/nginx/soft/imagick-3.0.1/imagick_class.c:9534: error: for each function it appears in.)
/usr/local/src/nginx/soft/imagick-3.0.1/imagick_class.c:9534: error: ‘CHECKUID_NO_ERRORS’ undeclared (first use in this function)
make: *** [imagick_class.lo] Error 1  ) 
如果遇到以下报错信息:
checking for re2c... no
configure: WARNING: You will need re2c 0.13.4 or later if you want to regenerate PHP parsers.
checking for gawk... gawk
checking whether to enable the imagick extension... yes, shared
checking whether to enable the imagick GraphicsMagick backend... no
checking ImageMagick MagickWand API configuration program... configure: error: not found. Please provide a path to MagickWand-config or Wand-config program.
安装以下软件:(安装时,请查看是否已经安装)
yum install libX11-devel libXext-devel libXt-devel #(解决下面的rpm包的依赖问题)
rpm -ivh ImageMagick-devel-6.2.8.0-4.el5_5.3.x86_64.rpm  #(下载地址:
ftp://rpmfind.net/linux/centos/5.7/os/x86_64/CentOS/ImageMagick-devel-6.2.8.0-4.el5_5.3.x86_64.rpm)
如果需要的话可以编译安装:MagickWandForPHP
#(下载地址http://www.magickwand.org/download/php/MagickWandForPHP-1.0.9.tar.gz) 
 
 
 
  1. tar zxvf memcache-3.0.6.tgz  #(此时为最新测试版本)  
  2. cd memcache-3.06  
  3. /usr/local/php-5.4.0/bin/phpize  
  4. ./configure --enable-memcache --with-php-config=/usr/local/php-5.4.0/bin/php-config  
  5. make  
  6. make install 

 (#注:之前的版本为memcache-2.2.6.tgz,这里不适用此版本的原因是,它会产生以下错误信息:

/usr/local/php-5.4.0/bin/php -v
eAccelerator requires Zend Engine API version 220090626.
The Zend Engine API version 220100525 which is installed, is newer.
Contact eAccelerator at http://eaccelerator.net for a later version of eAccelerator.
PHP Warning:  PHP Startup: memcache: Unable to initialize module
Module compiled with module API=20090626
PHP    compiled with module API=20100525
These options need to match
 in Unknown on line 0 )
##意思是memcache模块没有初始化,其实就是没有调用成功,造成此原因就是因为此2.2.6版本模块不支持php-5.4.0,模块编译使用的API为20090626,而php使用的API为20100525它们不匹配,只有匹配时才能成功,使用3.06的时候就会成功,如果有正式版尽量采用正式版,此时还没有这个版本的正式版,因此为了解决问题暂时使用此测试版本### 
以下版本仍然有问题,需更高版本才行,步骤一样。因此不建议升级到php-5.4.0,因为到目前为止eaccelerator没有更高版本。有新版本替换即可升级php-5.4.0了!
 
 
 
  1. tar jxvf eaccelerator-0.9.6.1.tar.bz2  
  2. cd eaccelerator-0.9.6.1/  
  3. /usr/local/php-5.4.0/bin/phpize  
  4. ./configure --enable-eaccelerator=shared --with-php-config=/usr/local/php-5.4.0/bin/php-config  
  5. make  
  6. make install 

 ####注:此版本到目前为止为最新版本,使用此版本来支持php-5.4.0的话,仍然会有问题,如同memcahce一样。如下信息:

/usr/local/php-5.4.0/bin/php -v
eAccelerator requires Zend Engine API version 220090626.
The Zend Engine API version 220100525 which is installed, is newer.
Contact eAccelerator at http://eaccelerator.net for a later version of eAccelerator.
PHP Warning:  PHP Startup: eAccelerator: Unable to initialize module
Module compiled with module API=20090626
PHP    compiled with module API=20100525
These options need to match
 in Unknown on line 0 
假如以上都解决了,进行以下步骤,当然其他的php版本升级也类似于此!只需选对相应模块的版本即可! 
修改php.ini文件
 
 
 
  1. vi /usr/local/php-5.4.0/etc/php.ini   

查找到:extension_dir = "./"

修改为:
extension_dir = "/usr/local/php-5.4.0/lib/php/extensions/no-debug-non-zts-20100525/"
并在此行后增加以下几行,然后保存:
extension = "eaccelerator.so"
extension = "imagick.so"
extension = "memcache.so" 
配置eAccelerator加速PHP:
mkdir -p /usr/local/php-5.4.0/eaccelerator_cache
vi /usr/local/php-5.4.0/etc/php.ini
按shift+g键跳到配置文件的最末尾,加上以下配置信息:
[eaccelerator]
zend_extension="/usr/local/php-5.4.0/lib/php/extensions/no-debug-non-zts-20100525/eaccelerator.so"
eaccelerator.shm_size="64"
eaccelerator.cache_dir="/usr/local/php-5.4.0/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.ini配置文件对新的php.ini文件进行修改!
创建php-fpm配置文件:
mv /usr/local/php-5.4.0/etc/php-fpm.conf /usr/local/php-5.4.0/etc/php-fpm.conf.old
把以前的php-fpm.conf文件复制到/usr/local/php-5.4.0/etc/目录即可!
或者新建一个,参照以前的配置对php-fpm.conf进行配置!
如果运行php时对php.ini进行更改,它会自动生效。
停掉之前的php-fpm服务,启用新的php-fpm。
/usr/local/php-5.4.0/sbin/php-fpm start
还有其他参数,包括:start|stop|quit|restart|reload|logrotate
 
本文是正对php-5.3.10升级到php-5.4.0版本,当然eaccelerator版本的问题还没有解决,如果是其他版本的升级,eaccelerator应该没有问题!当然我这里是内部测试机的环境,如果是线上的当然应该先对版本进行一个评估,确定有升级的必要!还要做好相应文件的备份,以防发生生产事故!以上只是我的一个操作过程,当然还不是很完善,请多多指教,谢谢!
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值