One, back up the original PHP file
To view an existing PHP version:
Backup, because it is not an overlay installation, here can also not backup, but, as a daily operating habits, backup is very necessary.
[[email protected] ~]# cd /usr/local/[[email protected] local]# cp -a php php5538
Second, download the latest stable version of PHP decompression 7.2.2
[[email protected] ~]# cd soft[[email protected] soft]# wget http://cn2.php.net/distributions/php-7.2.2.tar.bz2[[email protected] soft]# tar xf php-7.2.2.tar.bz2[[email protected] soft]# cd php-7.2.2/
Third, check the previous PHP configure information
Upgrade nature to reinstall, then the previous configure naturally want to know, how to view the previous configure information, there are generally two methods, the first, is through the phpinfo () information:
The second, by way of command:
[[email protected] ~]# php -i | grep configureConfigure 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‘
Extract the Configure command through SED:
[[email protected] ~]# 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
Four, start compiling the installation php7.2.2
[[email protected] 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
A warning message will be reported in the Configure process:
configure: WARNING: unrecognized options: --with-mysql, --with-mcrypt, --enable-gd-native-ttf
Indicates that php7.2.2 does not support the above three options, delete can be.
Start compiling below:
[[email protected] php-7.2.2]# make && make install
This process is time consuming and needs to be patiently awaited.
An error will be reported here:
/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 statusmake: *** [sapi/cli/php] Error 1
Error hint missing libiconv This library, what is missing anything.
wget http://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.13.1.tar.gztar xf libiconv-1.13.1.tar.gzcd libiconv-1.13.1/./configure --prefix=/usr/local/libiconvmake && make install
After installation, you need to add the--with-iconv=/usr/local/libiconv parameter when configure, and then compile again without error.
Five, copy modify config file, start php-fpm
[[email protected] local]# cp php/etc/php.ini php7/etc/[[email protected] local]# cp php/etc/php-fpm.conf php7/etc/[[email protected] ~]# service php-fpm stop Gracefully shutting down php-fpm . done#关闭原来的php-fpm
Modify Php-fpm.conf
[global]pid = /usr/local/php7/var/run/php-fpm.piderror_log = /usr/local/php7/var/log/php-fpm.log
Delete/usr/local/php Directory
[[email protected] local]# rm -rf php
Create a soft link to php7
[[email protected] local]# ln -sv php7 php
Start PHP-FPM
[[email protected] 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
An error indicates that the Redis extension is not installed.
Vi. Installing the Redis extension
Https://github.com/phpredis/phpredis/archive/php7.zip
unzip php7.zipcd soft/phpredis-php7//usr/local/php7/bin/phpize./configure --with-php-config=/usr/local/php7/bin/php-configmake && make install
Add the following line in the php.ini
extension=redis.so
Restart PHP-FPM
[[email protected] etc]# service php-fpm restart Gracefully shutting down php-fpm . doneStarting php-fpm done
View PHP Version
[[email protected] etc]# php -vPHP 7.2.2 (cli) (built: Feb 23 2018 19:25:46) ( NTS )Copyright (c) 1997-2018 The PHP GroupZend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies
View Phpinfo ()
At this point, the PHP upgrade is complete.
CentOS7 under PHP5.5.38 upgrade PHP7.2.2