lingwu

实验环境:CentOS Linux release 7.3.1611 

1.查看php版本有两种方法,显示结果相同。 第一种

# /usr/local/php/bin/php -v

 第二种

# php  -v
PHP 7.1.0 (cli) (built: Dec 17 2016 17:00:32) ( ZTS )
Copyright (c) 1997-2016 The PHP Group
Zend Engine v3.1.0-dev, Copyright (c) 1998-2016 Zend Technologies
with Zend OPcache v7.1.0, Copyright (c) 1999-2016, by Zend Technologies

 

 2.升级前需要找到之前的configure配置模块信息,做到升级前后是一致,否则可能会影响网站正常访问,若不记得之前的configure信息,可以写个phpinfo探针查找即可,或者使用以下命令

# php -i | grep configure

Configure Command => \'./configure\' \'--prefix=/usr/local/php\' \'--with-config-file-path=/usr/local/php/etc\' \'--with-fpm-user=www\' \'--with-fpm-group=www\' \'--with-iconv-dir\' \'--with-freetype-dir\' \'--with-jpeg-dir\' \'--with-png-dir\' \'--with-zlib\' \'--with-libxml-dir\' \'--enable-xml\' \'--disable-rpath\' \'--enable-bcmath\' \'--enable-shmop\' \'--enable-sysvsem\' \'--enable-inline-optimization\' \'--with-curl\' \'--enable-mbregex\' \'--enable-fpm\' \'--enable-mbstring\' \'--with-mcrypt\' \'--with-gd\' \'--enable-gd-jis-conv\' \'--enable-gd-native-ttf\' \'--with-openssl\' \'--with-mhash\' \'--enable-pcntl\' \'--enable-sockets\' \'--with-xmlrpc\' \'--enable-zip\' \'--enable-soap\' \'--enable-opcache\' \'--with-libmbfl\' \'--with-onig\' \'--enable-pdo\' \'--with-mysqli=mysqlnd\' \'--with-pdo-mysql=mysqlnd\' \'--with-pdo-mysql\' \'--enable-mysqlnd-compression-support\' \'--with-pear\' \'--enable-maintainer-zts\' \'--enable-session\' \'--with-gettext\'

 

以上信息稍作修改后,即可安装配置使用。

3.重要:先备份老版本php,以备升级失败后快速回滚

 # mv /usr/local/php /usr/local/php7.1.bak
 # mkdir /renwole
 # cd /renwole
 # wget http://am1.php.net/distributions/php-7.1.5.tar.gz
 # tar zxvf php-7.1.5.tar.gz
 # cd php-7.1.5
 # ./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --with-fpm-user=www --with-fpm-group=www --with-iconv-dir --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir --enable-xml --disable-rpath --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --with-curl --enable-mbregex --enable-fpm --enable-mbstring --with-mcrypt --with-gd --enable-gd-jis-conv --enable-gd-native-ttf --with-openssl --with-mhash --enable-pcntl --enable-sockets --with-xmlrpc --enable-zip --enable-soap --enable-opcache --with-libmbfl --with-onig --enable-pdo --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --with-pdo-mysql --enable-mysqlnd-compression-support --with-pear --enable-maintainer-zts --enable-session --with-gettext

 PHP编译完成后,你会看到 “Thank you for using PHP.” 字样,表示编译完成,执行以下安装命令;

# make && make install
这个过程有些慢,但不影响你的网站正常访问,耐心等待…

4.php完成升级安装配置后,开始拷贝php配置文件

# cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf
# cp /renwole/php-7.1.5/php.ini-development /usr/local/php/etc/php.ini
# cp /usr/local/php/etc/php-fpm.d/www.conf.default /usr/local/php/etc/php-fpm.d/www.conf
这个过程有些慢,但不影响你的网站正常访问,耐心等待…或者沿用老版php配置文件(如果PHP版本跨度不大,建议使用老版本php.ini,否则php配置文件中的很多东西需要重新配置),\cp -rf表示覆盖无提示
# \cp -rf /usr/local/php7.1.0.bak/etc/php-fpm.conf /usr/local/php/etc/php-fpm.conf
# \cp -rf /usr/local/php7.1.0.bak/etc/php.ini /usr/local/php/etc/php.ini
# \cp -rf /usr/local/php7.1.0.bak/etc/php-fpm.d/www.conf /usr/local/php/etc/php-fpm.d/www.conf

 

5.现在重启php-fpm

# systemctl restart php-fpm.server

 

6.再次查看php版本
# /usr/local/php/bin/php -v

 

PHP 7.1.5 (cli) (built: May 11 2017 16:18:43) ( ZTS )
Copyright (c) 1997-2017 The PHP Group
Zend Engine v3.1.0, Copyright (c) 1998-2017 Zend Technologies
with Zend OPcache v7.1.5, Copyright (c) 1999-2017, by Zend Technologies

分类:

技术点:

相关文章: