如何在 CentOS 8 上安装 PHP 7.4

PHP 是最常用的服务器端编程语言之一。
许多流行的 CMS 和框架(例如 WordPress、Magento 和 Laravel)都是用 PHP 构建的。

在本教程中,我们将讨论如何在 CentOS 8 上安装 PHP 7.4.
在选择要安装的 PHP 版本之前,请确保应用程序支持它。

01 PHP 7.2 可从默认的 CentOS 8 存储库安装。
要安装 PHP 7.4 ,我们需要启用 Remi 存储库,如下所示:

$sudo dnf install epel-release -y
$sudo dnf install https://rpms.remirepo.net/enterprise/remi-release-8.rpm -y

02 安装完成后,运行以下命令以获取所有可用 PHP 版本的列表:

$dnf module list php
Remi's Modular repository for Enterprise Linux 8 - x86_64                                                                           872 kB/s | 565 kB     00:00
Safe Remi's RPM repository for Enterprise Linux 8 - x86_64                                                                          1.6 MB/s | 1.5 MB     00:00
CentOS-8 - AppStream
Name                           Stream                            Profiles                                            Summary
php                            7.2 [d]                           common [d], devel, minimal                          PHP scripting language
php                            7.3                               common, 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

03 现在让我们通过运行以下命令来启用 remi-7.4 PHP 模块:

$sudo dnf module enable php:remi-7.4

04 以下命令将安装 PHP 和一些最常见的 PHP 模块:

$sudo dnf install php php-cli php-common

注意:如果我们想配置 PHP 以与 Nginx 一起使用,PHP FPM 作为依赖项安装并用作 FastCGI 服务器。
所以,不要忘记通过运行 sudo systemctl enable --now php-fpm来启动 php-fpm 守护进程。

05 最后,安装完成后,运行以下命令以获取 PHP 版本:

$php -v
PHP 7.4.5 (cli) (built: Apr 14 2016 12:54:33) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
    with Zend OPcache v7.4.5, Copyright (c), by Zend Technologies
日期:2020-06-02 22:18:55 来源:oir作者:oir