centos yum php 7.x 无需删除升级的方法

  • Post category:Linux

centos yum php7.x无需删除升级的方法攻略

CentOS 7 默认版本的PHP是5.x,但是随着PHP 7的推出,越来越多的Web开发人员开始尝试升级。本文将介绍CentOS 7下yum安装PHP 7.x的无需删除升级的方法。

第一步:添加Webtatic仓库

Webtatic仓库的rpm包可以提供PHP 7的二进制yum安装包。使用下列命令添加Webatic仓库:

rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm

第二步:安装PHP 7.x

执行下列命令来安装PHP 7.x:

yum -y install php70w

请确保使用合适的版本号来安装PHP 7.x(比如 php72w)。

示例:

[root@localhost ~]# rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm
Retrieving https://mirror.webtatic.com/yum/el7/webtatic-release.rpm
warning: /var/tmp/rpm-tmp.NqOdvH: Header V4 RSA/SHA1 Signature, key ID cf4c4f9c: NOKEY
Preparing...                          ################################# [100%]
Updating / installing...
   1:webtatic-release-7-3           ################################# [100%]
[root@localhost ~]# yum -y install php70w
Loaded plugins: fastestmirror, langpacks
Determining fastest mirrors
 * base: mirrors.aliyun.com
 * epel: mirrors.aliyun.com
 * extras: mirrors.aliyun.com
 * remi-safe: mirror.23media.com
 * updates: mirrors.aliyun.com
Resolving Dependencies
--> Running transaction check
---> Package php70w.x86_64 0:7.0.33-1.w7 will be installed
--> Processing Dependency: php70w-cli(x86-64) = 7.0.33-1.w7 for package: php70w-7.0.33-1.w7.x86_64
--> Processing Dependency: php70w-common(x86-64) = 7.0.33-1.w7 for package: php70w-7.0.33-1.w7.x86_64
--> Processing Dependency: php70w-json(x86-64) = 7.0.33-1.w7 for package: php70w-7.0.33-1.w7.x86_64
--> Processing Dependency: php70w-mbstring(x86-64) = 7.0.33-1.w7 for package: php70w-7.0.33-1.w7.x86_64
--> Processing Dependency: php70w-pdo(x86-64) = 7.0.33-1.w7 for package: php70w-7.0.33-1.w7.x86_64
--> Processing Dependency: php70w-xml(x86-64) = 7.0.33-1.w7 for package: php70w-7.0.33-1.w7.x86_64
--> Running transaction check
---> Package php70w-cli.x86_64 0:7.0.33-1.w7 will be installed
--> Processing Dependency: /bin/sh for package: php70w-cli-7.0.33-1.w7.x86_64
---> Package php70w-common.x86_64 0:7.0.33-1.w7 will be installed
---> Package php70w-json.x86_64 0:7.0.33-1.w7 will be installed
---> Package php70w-mbstring.x86_64 0:7.0.33-1.w7 will be installed
---> Package php70w-pdo.x86_64 0:7.0.33-1.w7 will be installed
--> Processing Dependency: php70w-pdo(x86-64) = 7.0.33-1.w7 for package: php70w-xml-7.0.33-1.w7.x86_64
--> Processing Dependency: libpq.so.5()(64bit) for package: php70w-pdo-7.0.33-1.w7.x86_64
---> Package php70w-xml.x86_64 0:7.0.33-1.w7 will be installed
--> Running transaction check
---> Package postgresql-libs.x86_64 0:9.2.24-4.el7_8 will be installed
---> Package php70w-cli.x86_64 0:7.0.33-1.w7 will be installed
--> Processing Dependency: /bin/sh for package: php70w-cli-7.0.33-1.w7.x86_64
---> Package php70w-pdo.x86_64 0:7.0.33-1.w7 will be installed
--> Processing Dependency: php70w-pdo(x86-64) = 7.0.33-1.w7 for package: php70w-xml-7.0.33-1.w7.x86_64
--> Running transaction check
---> Package php70w-cli.x86_64 0:7.0.33-1.w7 will be installed
--> Processing Dependency: /bin/sh for package: php70w-cli-7.0.33-1.w7.x86_64
---> Package php70w-pdo.x86_64 0:7.0.33-1.w7 will be installed
--> Processing Dependency: php70w-pdo(x86-64) = 7.0.33-1.w7 for package: php70w-xml-7.0.33-1.w7.x86_64
--> Running transaction check
---> Package php70w-cli.x86_64 0:7.0.33-1.w7 will be installed
--> Processing Dependency: /bin/sh for package: php70w-cli-7.0.33-1.w7.x86_64
---> Package php70w-xml.x86_64 0:7.0.33-1.w7 will be installed
--> Processing Dependency: libxslt.so.1(LIBXML2_1.0.11)(64bit) for package: php70w-xml-7.0.33-1.w7.x86_64
--> Processing Dependency: libxslt.so.1(LIBXML2_1.0.18)(64bit) for package: php70w-xml-7.0.33-1.w7.x86_64
--> Processing Dependency: libxslt.so.1(LIBXML2_1.0.22)(64bit) for package: php70w-xml-7.0.33-1.w7.x86_64
--> Processing Dependency: libxslt.so.1(LIBXML2_1.0.24)(64bit) for package: php70w-xml-7.0.33-1.w7.x86_64
--> Processing Dependency: libxslt.so.1(LIBXML2_1.0.25)(64bit) for package: php70w-xml-7.0.33-1.w7.x86_64
--> Processing Dependency: libxslt.so.1(LIBXML2_1.0.26)(64bit) for package: php70w-xml-7.0.33-1.w7.x86_64
--> Processing Dependency: libxslt.so.1(LIBXML2_1.0.28)(64bit) for package: php70w-xml-7.0.33-1.w7.x86_64
--> Processing Dependency: libxslt.so.1(LIBXML2_1.0.29)(64bit) for package: php70w-xml-7.0.33-1.w7.x86_64
--> Processing Dependency: libxslt.so.1()(64bit) for package: php70w-xml-7.0.33-1.w7.x86_64
--> Running transaction check
---> Package libxslt.x86_64 0:1.1.28-5.el7 will be installed
---> Package php70w-cli.x86_64 0:7.0.33-1.w7 will be installed
--> Processing Dependency: /bin/sh for package: php70w-cli-7.0.33-1.w7.x86_64
---> Package php70w-xml.x86_64 0:7.0.33-1.w7 will be installed
--> Processing Dependency: libxslt.so.1()(64bit) for package: php70w-xml-7.0.33-1.w7.x86_64
--> Running transaction check
---> Package php70w-cli.x86_64 0:7.0.33-1.w7 will be installed
--> Processing Dependency: /bin/sh for package: php70w-cli-7.0.33-1.w7.x86_64
---> Package php70w-xml.x86_64 0:7.0.33-1.w7 will be installed
--> Processing Dependency: libxslt.so.1()(64bit) for package: php70w-xml-7.0.33-1.w7.x86_64
--> Finished Dependency Resolution

Dependencies Resolved

============================================================================================================================
 Package                     Arch               Version                  Repository                                Size
============================================================================================================================
Installing:
 php70w                      x86_64             7.0.33-1.w7             webtatic                                  3.1 M
Installing for dependencies:
 libxslt                     x86_64             1.1.28-5.el7             base                                     242 k
 php70w-cli                  x86_64             7.0.33-1.w7             webtatic                                  4.7 M
 php70w-common               x86_64             7.0.33-1.w7             webtatic                                  1.1 M
 php70w-json                 x86_64             7.0.33-1.w7             webtatic                                   72 k
 php70w-mbstring             x86_64             7.0.33-1.w7             webtatic                                  1.3 M
 php70w-pdo                  x86_64             7.0.33-1.w7             webtatic                                  185 k
 php70w-xml                  x86_64             7.0.33-1.w7             webtatic                                  250 k
 postgresql-libs             x86_64             9.2.24-4.el7_8           updates                                   237 k

Transaction Summary
============================================================================================================================
Install  1 Package (+8 Dependent packages)

Total download size: 11 M
Installed size: 38 M
Downloading packages:
(1/9): libxslt-1.1.28-5.el7.x86_64.rpm                                                              | 242 kB  00:00:00     
(2/9): php70w-json-7.0.33-1.w7.x86_64.rpm                                                           |  72 kB  00:00:00     
(3/9): php70w-common-7.0.33-1.w7.x86_64.rpm                                                         | 1.1 MB  00:00:00     
(4/9): php70w-pdo-7.0.33-1.w7.x86_64.rpm                                                            | 185 kB  00:00:00     
(5/9): php70w-mbstring-7.0.33-1.w7.x86_64.rpm                                                       | 1.3 MB  00:00:00     
(6/9): php70w-cli-7.0.33-1.w7.x86_64.rpm                                                            | 4.7 MB  00:00:00     
(7/9): postgresql-libs-9.2.24-4.el7_8.x86_64.rpm                                                     | 237 kB  00:00:00     
(8/9): php70w-xml-7.0.33-1.w7.x86_64.rpm                                                            | 250 kB  00:00:00     
(9/9): php70w-7.0.33-1.w7.x86_64.rpm                                                                | 3.1 MB  00:00:00     
----------------------------------------------------------------------------------------------------------------------------
Total                                                                                       19 MB/s |  11 MB  00:00:00     
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : php70w-common-7.0.33-1.w7.x86_64                                                                      1/9 
  Installing : libxslt-1.1.28-5.el7.x86_64                                                                           2/9 
  Installing : postgresql-libs-9.2.24-4.el7_8.x86_64                                                                 3/9 
  Installing : php70w-cli-7.0.33-1.w7.x86_64                                                                         4/9 
  Installing : php70w-json-7.0.33-1.w7.x86_64                                                                        5/9 
  Installing : php70w-mbstring-7.0.33-1.w7.x86_64                                                                    6/9 
  Installing : php70w-pdo-7.0.33-1.w7.x86_64                                                                         7/9 
  Installing : php70w-xml-7.0.33-1.w7.x86_64                                                                         8/9 
  Installing : php70w-7.0.33-1.w7.x86_64                                                                             9/9 
  Verifying  : php70w-mbstring-7.0.33-1.w7.x86_64                                                                    1/9 
  Verifying  : php70w-cli-7.0.33-1.w7.x86_64                                                                         2/9 
  Verifying  : php70w-json-7.0.33-1.w7.x86_64                                                                        3/9 
  Verifying  : php70w-common-7.0.33-1.w7.x86_64                                                                      4/9 
  Verifying  : php70w-xml-7.0.33-1.w7.x86_64                                                                         5/9 
  Verifying  : libxslt-1.1.28-5.el7.x86_64                                                                           6/9 
  Verifying  : php70w-7.0.33-1.w7.x86_64                                                                             7/9 
  Verifying  : postgresql-libs-9.2.24-4.el7_8.x86_64                                                                 8/9 
  Verifying  : php70w-pdo-7.0.33-1.w7.x86_64                                                                         9/9 

Installed:
  php70w.x86_64 0:7.0.33-1.w7                                                                                            

Dependency Installed:
  libxslt.x86_64 0:1.1.28-5.el7                                                 
  php70w-cli.x86_64 0:7.0.33-1.w7                                              
  php70w-common.x86_64 0:7.0.33-1.w7                                           
  php70w-json.x86_64 0:7.0.33-1.w7                                             
  php70w-mbstring.x86_64 0:7.0.33-1.w7                                         
  php70w-pdo.x86_64 0:7.0.33-1.w7                                              
  php70w-xml.x86_64 0:7.0.33-1.w7                                              
  postgresql-libs.x86_64 0:9.2.24-4.el7_8                                       

Complete!

第三步:重启httpd服务器

使用下列命令重启httpd服务器:

systemctl restart httpd.service

示例

示例一

添加Webtatic仓库:

[root@localhost ~]# rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm
Retrieving https://mirror.webtatic.com/yum/el7/webtatic-release.rpm
warning: /var/tmp/rpm-tmp.d5qWiE: Header V4 RSA/SHA1 Signature, key ID cf4c4f9c: NOKEY
Preparing...                          ################################# [100%]
Updating / installing...
   1:webtatic-release-7-3           ################################# [100%]

执行下列命令安装PHP 7.x:

“`bash
[root@localhost ~]# yum -y install php70w
Loaded plugins: fastestmirror, langpacks
Determining fastest mirrors
* base: mirrors.aliyun.com
* epel: mirrors.aliyun.com
* extras: mirrors.aliyun.com
* remi-safe: mirror.23media.com
* updates: mirrors.aliyun.com
Resolving Dependencies
–> Running transaction check
—> Package php70w.x86_64 0:7.0.33-1.w7 will be installed
–> Processing Dependency: php70w-cli(x86-64) = 7.0.33-1.w7 for package: php70w-7.0.33-1.w7.x86_64
–> Processing Dependency: php70w-common(x86-64) = 7.0.33-1.w7 for package: php70w-7.0.33-1.w7.x86_64
–> Processing Dependency: