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.default /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。
service php-fpm restart  ##注意已經將php-fpm添加爲系統服務纔可以這樣
還有其他參數,包括:start|stop|quit|restart|reload|logrotate
 
本文是正對php-5.3.10升級到php-5.4.0版本,當然eaccelerator版本的問題還沒有解決,如果是其他版本的升級,eaccelerator應該沒有問題!當然我這裏是內部測試機的環境,如果是線上的當然應該先對版本進行一個評估,確定有升級的必要!還要做好相應文件的備份,以防發生生產事故!以上只是我的一個操作過程,當然還不是很完善,請多多指教,謝謝!
千萬別忘了提出您寶貴的意見哦,親!!!!
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章