如何在CentOS 8上安装PHP 7.4


PHP是PHP Hypertext Preprocessor的递归首字母缩写,是一种流行的服务器端脚本语言,用于Web开发以创建强大而动态的网站。

在本文中,您将学习如何在CentOS 8 Linux上安装PHP 7.4。

步骤1:添加EPEL和Remi存储库

首先,您需要添加EPEL&Remi存储库,从中可以在CentOS 8 Linux上安装PHP 7.4。

要在CentOS 8上安装并启用EPEL存储库,请执行以下dnf命令。

[root@localhost www.linuxboy.net]# dnf install https://dl.Fedoraproject.org/pub/epel/epel-release-latest-8.noarch.rpm

如何在CentOS 8上安装PHP 7.4 

要确认EPEL存储库的存在,请运行以下rpm命令。

[root@localhost www.linuxboy.net]# rpm -qa | grep epel
epel-release-8-7.el8.noarch

如何在CentOS 8上安装PHP 7.4

接下来,运行以下命令以添加Remi存储库。

[root@localhost www.linuxboy.net]# dnf install https://rpms.remirepo.net/enterprise/remi-release-8.rpm

如何在CentOS 8上安装PHP 7.4

再次,以验证Remi存储库的存在,运行命令。

[root@localhost www.linuxboy.net]# rpm -qa | grep remi
remi-release-8.0-4.el8.remi.noarch

如何在CentOS 8上安装PHP 7.4

步骤2:在CentOS 8上安装PHP 7.4

成功添加EPEL和Remi存储库后,执行以下命令以获取可用PHP模块流的列表。

[root@localhost www.linuxboy.net]# dnf module list php
Remi's Modular repository for Enterprise Linux  7.6 kB/s | 508 kB    01:06   
Safe Remi's RPM repository for Enterprise Linux  12 kB/s | 1.4 MB    01:54   
上次元数据过期检查:0:00:34 前,执行于 2019年11月07日 星期四 00时20分37秒。
CentOS-8 - AppStream
Name      Stream      Profiles                      Summary                 
php      7.2 [d]      common [d], devel, minimal    PHP scripting language   

Remi's Modular repository for Enterprise Linux 8 - x86_64
Name      Stream      Profiles                      Summary                 
php      remi-7.2    common [d], devel, minimal    PHP scripting language   
php      remi-7.3    common [d], devel, minimal    PHP scripting language   
php      remi-7.4    common [d], devel, minimal    PHP scripting language   

Hint: [d]efault, [e]nabled, [x]disabled, [i]nstalled

如何在CentOS 8上安装PHP 7.4

从上面的输出中,remi-7.4 是最新的PHP流,因此我们将启用模块流,如下所示。

[root@localhost www.linuxboy.net]# dnf module enable php:remi-7.4
上次元数据过期检查:0:00:38 前,执行于 2019年11月07日 星期四 00时21分47秒。
依赖关系解决。
================================================================================
 软件包            架构            版本                仓库              大小
================================================================================
Enabling module streams:
 httpd                              2.4                                       
 php                                remi-7.4                                 

事务概要
================================================================================

确定吗?[y/N]: y
完毕!

Switching module streams does not alter installed packages (see 'module enable' in dnf(8) for details)

如何在CentOS 8上安装PHP 7.4

启用PHP remi-7.4模块后,即可使用以下命令继续并安装PHP。 这还将安装许多其他软件包,例如Apache和Nginx模块。

[root@localhost www.linuxboy.net]# dnf install php php-cli php-common

如何在CentOS 8上安装PHP 7.4

要检查已安装的PHP版本,请运行命令。

[root@localhost www.linuxboy.net]# php -v
PHP 7.4.0RC5 (cli) (built: Oct 29 2019 08:49:19) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0-dev, Copyright (c) Zend Technologies
    with Zend OPcache v7.4.0RC5, Copyright (c), by Zend Technologies

如何在CentOS 8上安装PHP 7.4

从输出中,我们可以清楚地看到我们已经安装了PHP版本7.4! 现在,您可以继续使用PHP测试和部署应用程序。 现在就这样。 我们希望本指南对您有所帮助。

linuxboy的RSS地址:https://www.linuxboy.net/rssFeed.aspx

本文永久更新链接地址:https://www.linuxboy.net/Linux/2019-11/161300.htm

相关内容