CentOS7下PHP5.5.38升級PHP7.2.2
阿新 • • 發佈:2018-02-24
php7 php升級 redis lnmp 一,備份原先的php文件
查看現有php版本:
[root@localhost local]# php -v
PHP 5.5.38 (cli) (built: Oct 24 2017 15:58:09)
備份,由於不是覆蓋安裝,這裏也可以不備份,但是,作為日常操作習慣來說,備份還是很有必要的。
[root@localhost ~]# cd /usr/local/
[root@localhost local]# cp -a php php5538
二,下載解壓PHP的最新穩定版7.2.2
[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/
三,查看之前php的configure信息
升級自然要重新安裝,那麽之前的configure自然要知曉,怎麽查看之前的configure信息呢,一般來說有兩種方法,第一種,是通過phpinfo()信息:
第二種,通過命令的方式:
[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命令提取出來:
[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
四,開始編譯安裝php7.2.2
[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的過程中會報一個警告信息:
configure: WARNING: unrecognized options: --with-mysql, --with-mcrypt, --enable-gd-native-ttf
表示php7.2.2不支持以上三個選項,刪掉即可。
下面開始編譯:
[root@localhost php-7.2.2]# make && make install
這個過程非常耗時,需要耐心等待。
這裏會報一個錯誤:
/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這個庫,缺啥就裝啥。
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參數,然後再次編譯就不會報錯了
五,復制修改配置文件,啟動php-fpm
[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擴展沒有裝。
六,安裝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升級完成。
CentOS7下PHP5.5.38升級PHP7.2.2