查看现有php版本:php
[root@localhost local]# php -v PHP 5.5.38 (cli) (built: Oct 24 2017 15:58:09)
备份,因为不是覆盖安装,这里也能够不备份,可是,做为平常操做习惯来讲,备份仍是颇有必要的。mysql
[root@localhost ~]# cd /usr/local/ [root@localhost local]# cp -a php php5538
[root@localhost ~]# cd soft [root@localhost soft]# wget http://cn2.php.net/distributions/php-7.2.2.tar.bz2 [root@localhost soft]# tar xf php-7.2.2.tar.bz2 [root@localhost soft]# cd php-7.2.2/
升级天然要从新安装,那么以前的configure天然要知晓,怎么查看以前的configure信息呢,通常来讲有两种方法,第一种,是经过phpinfo()信息:
第二种,经过命令的方式:git
[root@localhost ~]# php -i | grep configure Configure Command => './configure' '--prefix=/usr/local/php' '--with-config-file-path=/usr/local/php/etc' '--with-config-file-scan-dir=/usr/local/php/conf.d' '--enable-fpm' '--with-fpm-user=www' '--with-fpm-group=www' '--with-mysql=mysqlnd' '--with-mysqli=mysqlnd' '--with-pdo-mysql=mysqlnd' '--with-iconv-dir' '--with-freetype-dir=/usr/local/freetype' '--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' '--enable-mbregex' '--enable-mbstring' '--with-mcrypt' '--enable-ftp' '--with-gd' '--enable-gd-native-ttf' '--with-openssl' '--with-mhash' '--enable-pcntl' '--enable-sockets' '--with-xmlrpc' '--enable-zip' '--enable-soap' '--with-gettext' '--disable-fileinfo' '--enable-opcache' '--enable-intl' '--with-xsl'
经过sed 将configure命令提取出来:github
[root@localhost ~]# php -i | grep configure | sed -e "s/Configure Command => //; s/'//g" ./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --with-config-file-scan-dir=/usr/local/php/conf.d --enable-fpm --with-fpm-user=www --with-fpm-group=www --with-mysql=mysqlnd --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --with-iconv-dir --with-freetype-dir=/usr/local/freetype --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 --enable-mbregex --enable-mbstring --with-mcrypt --enable-ftp --with-gd --enable-gd-native-ttf --with-openssl --with-mhash --enable-pcntl --enable-sockets --with-xmlrpc --enable-zip --enable-soap --with-gettext --disable-fileinfo --enable-opcache --enable-intl --with-xsl
[root@localhost php-7.2.2]# ./configure --prefix=/usr/local/php7 \ --with-config-file-path=/usr/local/php7/etc \ --with-config-file-scan-dir=/usr/local/php7/conf.d \ --enable-fpm \ --with-fpm-user=www \ --with-fpm-group=www \ --with-mysql=mysqlnd \ --with-mysqli=mysqlnd \ --with-pdo-mysql=mysqlnd \ --with-iconv-dir \ --with-freetype-dir=/usr/local/freetype \ --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 \ --enable-mbregex \ --enable-mbstring \ --with-mcrypt \ --enable-ftp \ --with-gd \ --enable-gd-native-ttf \ --with-openssl \ --with-mhash \ --enable-pcntl \ --enable-sockets \ --with-xmlrpc \ --enable-zip \ --enable-soap \ --with-gettext \ --disable-fileinfo \ --enable-opcache \ --enable-intl --with-xsl
configure的过程当中会报一个警告信息:redis
configure: WARNING: unrecognized options: --with-mysql, --with-mcrypt, --enable-gd-native-ttf
表示php7.2.2不支持以上三个选项,删掉便可。sql
下面开始编译:api
[root@localhost php-7.2.2]# make && make install
这个过程很是耗时,须要耐心等待。php7
这里会报一个错误:curl
/root/soft/php-7.2.2/ext/xmlrpc/libxmlrpc/encodings.c:65: undefined reference to `libiconv_open' /root/soft/php-7.2.2/ext/xmlrpc/libxmlrpc/encodings.c:73: undefined reference to `libiconv' /root/soft/php-7.2.2/ext/xmlrpc/libxmlrpc/encodings.c:93: undefined reference to `libiconv_close' /root/soft/php-7.2.2/ext/xmlrpc/libxmlrpc/encodings.c:93: undefined reference to `libiconv_close' collect2: error: ld returned 1 exit status make: *** [sapi/cli/php] Error 1
报错提示缺乏libiconv这个库,缺啥就装啥。socket
wget http://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.13.1.tar.gz tar xf libiconv-1.13.1.tar.gz cd libiconv-1.13.1/ ./configure --prefix=/usr/local/libiconv make && make install
安装完后须要在configure时加入--with-iconv=/usr/local/libiconv参数,而后再次编译就不会报错了
[root@localhost local]# cp php/etc/php.ini php7/etc/ [root@localhost local]# cp php/etc/php-fpm.conf php7/etc/ [root@localhost ~]# service php-fpm stop Gracefully shutting down php-fpm . done #关闭原来的php-fpm
修改php-fpm.conf
[global] pid = /usr/local/php7/var/run/php-fpm.pid error_log = /usr/local/php7/var/log/php-fpm.log
删除/usr/local/php目录
[root@localhost local]# rm -rf php
建立指向php7的软连接
[root@localhost local]# ln -sv php7 php
启动php-fpm
[root@localhost etc]# service php-fpm start Starting php-fpm [23-Feb-2018 20:48:41] NOTICE: PHP message: PHP Warning: PHP Startup: Unable to load dynamic library '/usr/local/php/lib/php/extensions/no-debug-non-zts-20121212/redis.so' (tried: /usr/local/php/lib/php/extensions/no-debug-non-zts-20121212/redis.so (/usr/local/php/lib/php/extensions/no-debug-non-zts-20121212/redis.so: undefined symbol: zval_used_for_init), /usr/local/php7/lib/php/extensions/no-debug-non-zts-20170718//usr/local/php/lib/php/extensions/no-debug-non-zts-20121212/redis.so.so (/usr/local/php7/lib/php/extensions/no-debug-non-zts-20170718//usr/local/php/lib/php/extensions/no-debug-non-zts-20121212/redis.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0 [23-Feb-2018 20:48:41] ERROR: An another FPM instance seems to already listen on /tmp/php-cgi.sock [23-Feb-2018 20:48:41] ERROR: FPM initialization failed failed
报错了,提示redis扩展没有装。
下载地址
https://github.com/phpredis/phpredis/archive/php7.zip
unzip php7.zip cd soft/phpredis-php7/ /usr/local/php7/bin/phpize ./configure --with-php-config=/usr/local/php7/bin/php-config make && make install
在php.ini中添加以下一行
extension=redis.so
重启php-fpm
[root@localhost etc]# service php-fpm restart Gracefully shutting down php-fpm . done Starting php-fpm done
查看php版本
[root@localhost etc]# php -v PHP 7.2.2 (cli) (built: Feb 23 2018 19:25:46) ( NTS ) Copyright (c) 1997-2018 The PHP Group Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies
查看phpinfo()至此,php升级完成。