CentOS 7 安装和升级 PHP 7.x
2022-07-28 15:20:24
141
{{single.collect_count}}

说明如何在 CentOS 7 安装 PHP 7.x 的各种版本。

CentOS
安装所须软件:
[root@localhost ~]# yum install -y wget yum-utils
由于较新版的 PHP7 并末收录在 CentOS 7,因此须先更新软体来源:

[root@localhost ~]# wget https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm[root@localhost ~]# wget http://rpms.remirepo.net/enterprise/remi-release-7.rpm[root@localhost ~]# rpm -Uvh epel-release-latest-7.noarch.rpm[root@localhost ~]# rpm -Uvh remi-release-7.rpm

移除下载的档案:

[root@localhost ~]# rm epel-release-latest-7.noarch.rpm remi-release-7.rpm

指定 PHP 安装版本
更换 remi-php72 来指定欲安装的 PHP 版本:

PHP 7:remi-php70。
PHP 7.1:remi-php71。
PHP 7.2:remi-php72。

[root@localhost ~]# yum-config-manager --enable remi-php72 Loaded plugins: fastestmirror======================================= repo: remi-php72 ====== ==================================[remi-php72]async = Truebandwidth = 0

… 以下省略 …

安装 PHP 与相关软体
会直接安装上述指定的 PHP 版本:

[root@localhost ~]# yum install -y php php-mysqlnd php-pdo php-xml php-pear php-devel php-mbstring re2c gcc-c++ gcc

检查 PHP 版本

[root@localhost ~]# php -vPHP 7.2.5 (cli) (built: Apr 24 2018 19:12:06) ( NTS )Copyright (c) 1997-2018 The PHP GroupZend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies
回帖
全部回帖({{commentCount}})
{{item.user.nickname}} {{item.user.group_title}} {{item.friend_time}}
{{item.content}}
{{item.comment_content_show ? '取消' : '回复'}} 删除
回帖
{{reply.user.nickname}} {{reply.user.group_title}} {{reply.friend_time}}
{{reply.content}}
{{reply.comment_content_show ? '取消' : '回复'}} 删除
回帖
收起
没有更多啦~
{{commentLoading ? '加载中...' : '查看更多评论'}}