查看現有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升級完成。