CentOS 7 安裝和升級 PHP 7.x

說明如何在 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 = True
bandwidth = 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 -v
PHP 7.2.5 (cli) (built: Apr 24 2018 19:12:06) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章