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

原文

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