linux下php的升级问题+详细

在搭建网站,或者其他的时候会提示php版本低或不安全等问题

下面以升级php2.4为例

查看现在PHP的版本

$ php -v

PHP 7.1.2 (cli) (built: Mar 11 2017 23:57:39) ( NTS )

Copyright (c) 1997-2017 The PHP Group

Zend Engine v3.1.0, Copyright (c) 1998-2017 Zend Technologies

现在php7.1安装在“/usr/local/webserver/php7/”目录下:

$ ll /usr/local/bin/php

lrwxrwxrwx 1 root root 33 Mar 10  2017 /usr/local/bin/php -> /usr/local/webserver/php7/bin/php*

下载并安装最新版PHP7.2.4:

查看PHP最新版本, 目前最新稳定版是2018329日发布的PHP 7.2.4

Current Stable PHP 7.2.4 (Changelog)

php-7.2.4.tar.bz2 (sig) [14,273Kb] 29 Mar 2018

php-7.2.4.tar.gz (sig) [17,876Kb] 29 Mar 2018

php-7.2.4.tar.xz (sig) [11,750Kb] 29 Mar 2018

我们选择下载最小的一个格式的“php-7.2.4.tar.xz”

使用 wget 命令下载文件, 再使用 xz 命令解压称 .tar 格式的文件,再使用 tar 命令解压。

$ cd /usr/local/webserver/

$ wget http://am1.php.net/get/php-7.2.4.tar.xz/from/this/mirror php-7.2.4.tar.xz

$ xz -d php-7.2.4.tar.xz

$ tar -xvf php-7.2.4.tar

查看上个安装版本的配置

$ php -i | grep configure

Configure Command =>  './configure'  '--prefix=/usr/local/webserver/php7' '--with-config-file-path=/usr/local/webserver/php7/etc' '--with-zlib-dir' '--with-freetype-dir' '--enable-mbstring' '--with-libxml-dir=/usr' '--enable-soap' '--enable-calendar' '--with-curl' '--with-mcrypt' '--with-gd' '--disable-rpath' '--enable-inline-optimization' '--with-bz2' '--with-zlib' '--enable-sockets' '--enable-sysvsem' '--enable-sysvshm' '--enable-pcntl' '--enable-mbregex' '--enable-exif' '--enable-bcmath' '--with-mhash' '--enable-zip' '--with-pcre-regex' '--with-pdo-mysql' '--with-mysqli' '--with-mysql-sock=/var/run/mysqld/mysqld.sock' '--with-jpeg-dir=/usr' '--with-png-dir=/usr' '--enable-gd-native-ttf' '--with-openssl' '--with-fpm-user=www-data' '--with-fpm-group=www-data' '--enable-ftp' '--with-imap' '--with-imap-ssl' '--with-kerberos' '--with-gettext' '--with-xmlrpc' '--with-xsl' '--enable-opcache' '--enable-fpm'

格式一下命令,之前使用反斜线(\)执行的命令,显示成了单引号, 再将 单引号转换成 反斜线, 具体配置命令如下:

./configure --prefix=/usr/local/webserver/php7.2 \

        --with-config-file-path=/usr/local/webserver/php7.2/etc \

        --with-zlib-dir \

        --with-freetype-dir \

        --enable-mbstring \

        --with-libxml-dir=/usr \

        --enable-soap \

        --enable-calendar \

        --with-curl \

        --with-mcrypt \

        --with-gd \

        --disable-rpath \

        --enable-inline-optimization \

        --with-bz2 \

        --with-zlib \

        --enable-sockets \

        --enable-sysvsem \

        --enable-sysvshm \

        --enable-pcntl \

        --enable-mbregex \

        --enable-exif \

        --enable-bcmath \

        --with-mhash \

        --enable-zip \

        --with-pcre-regex \

        --with-pdo-mysql \

        --with-mysqli \

        --with-mysql-sock=/var/run/mysqld/mysqld.sock \

        --with-jpeg-dir=/usr \

        --with-png-dir=/usr \

        --enable-gd-native-ttf \

        --with-openssl \

        --with-fpm-user=www-data \

        --with-fpm-group=www-data \

        --enable-ftp \

        --with-imap \

        --with-imap-ssl \

        --with-kerberos \

        --with-gettext \

        --with-xmlrpc \

        --with-xsl \

        --enable-opcache \

        --enable-fpm

稍等一会,等配置执行完毕后,再接着编译和安装命令,执行:

 

$ make

 

$ make install

 

使用全路径查看php版本:

$ /usr/local/webserver/php7.2/bin/php -v

PHP 7.2.4 (cli) (built: Apr  7 2018 16:51:41) ( NTS )

Copyright (c) 1997-2018 The PHP Group

Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies

删除原来的软连接,建立新软连接到/usr/local/bin/目录:

$ rm /usr/local/bin/php*

$ sudo ln -s /usr/local/webserver/php7.2/bin/php* /usr/local/bin/

现在 php -v 就可以看到新版本了:

$ php -v

PHP 7.2.4 (cli) (built: Apr  7 2018 16:51:41) ( NTS )

Copyright (c) 1997-2018 The PHP Group

Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies

复制原来的配置文件到新的目录:

$ cp /usr/local/webserver/php7/etc/php-fpm.conf /usr/local/webserver/php7.2/etc/php-fpm.conf

$ cp /usr/local/webserver/php7/etc/php-fpm.d/www.conf /usr/local/webserver/php7.2/etc/php-fpm.d/www.conf

重启

使用 ps 查看php进程,使用 kill 结束开启中的php进程, 再重启php-fpm:

$ ps -ef |grep php

$ sudo kill -9 2719

$ sudo /usr/local/webserver/php7.2/sbin/php-fpm

原文

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章