如何在CentOS 8 / RHEL 8上安装PHP 8.0

广告

PHP是嵌入在HTML中的一种开源编程语言。 它主要用于创建动态网站,例如博客,电子商务网站等。RasmusLerdorf于1994年创建了它。

CentOS 8 / RHEL 8默认带有PHP v7.2。

在这篇文章中,我们将看到如何在CentOS 8 / RHEL 8上安装PHP 8.0。

添加Remi存储库

Remi,一个第三方存储库,为Red Hat Enterprise Linux提供了多个PHP版本(8.0 / 7.4 / 7.3 / 7.2)。

Remi系统信息库要求在系统上启用EPEL系统信息库。 因此,在系统上安装最新的EPEL存储库自动配置rpm,以启用EPEL存储库。

dnf install -y https://dl.fedoraproject.org/pub/epel/epel-release-latest-8.noarch.rpm

然后,使用以下命令安装Remi存储库自动配置软件包。

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

输出:

CentOS-8 - AppStream                                                               1.4 MB/s | 5.8 MB     00:04    
CentOS-8 - Base                                                                    128 kB/s | 2.2 MB     00:17    
CentOS-8 - Extras                                                                  3.8 kB/s | 8.6 kB     00:02    
CentOS-8 - PowerTools                                                              764 kB/s | 1.9 MB     00:02    
Extra Packages for Enterprise Linux Modular 8 - x86_64                              30 kB/s |  98 kB     00:03    
Extra Packages for Enterprise Linux 8 - x86_64                                     4.6 MB/s | 8.4 MB     00:01    
Google Cloud SDK                                                                   5.4 MB/s |  22 MB     00:04    
Google Compute Engine                                                              2.1 kB/s | 6.9 kB     00:03    
remi-release-8.rpm                                                                  15 kB/s |  23 kB     00:01    
Dependencies resolved.
===================================================================================================================
 Package                      Arch                Version                          Repository                 Size
===================================================================================================================
Installing:
 remi-release                 noarch              8.1-2.el8.remi                   @commandline               23 k
Upgrading:
 centos-release               x86_64              8.2-2.2004.0.2.el8               BaseOS                     21 k
Installing dependencies:
 centos-gpg-keys              noarch              8.2-2.2004.0.2.el8               BaseOS                     12 k
 centos-repos                 x86_64              8.2-2.2004.0.2.el8               BaseOS                     13 k

Transaction Summary
===================================================================================================================
Install  3 Packages
Upgrade  1 Package

Total size: 69 k
Total download size: 46 k
Downloading Packages:
(1/3): centos-gpg-keys-8.2-2.2004.0.2.el8.noarch.rpm                                12 kB/s |  12 kB     00:01    
(2/3): centos-repos-8.2-2.2004.0.2.el8.x86_64.rpm                                   12 kB/s |  13 kB     00:01    
(3/3): centos-release-8.2-2.2004.0.2.el8.x86_64.rpm                                 20 kB/s |  21 kB     00:01    
-------------------------------------------------------------------------------------------------------------------
Total                                                                               12 kB/s |  46 kB     00:03
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
  Preparing        :                                                                                           1/1 
  Running scriptlet: centos-gpg-keys-8.2-2.2004.0.2.el8.noarch                                                 1/1 
  Installing       : centos-gpg-keys-8.2-2.2004.0.2.el8.noarch                                                 1/5 
  Upgrading        : centos-release-8.2-2.2004.0.2.el8.x86_64                                                  2/5 
  Installing       : centos-repos-8.2-2.2004.0.2.el8.x86_64                                                    3/5 
  Installing       : remi-release-8.1-2.el8.remi.noarch                                                        4/5 
  Cleanup          : centos-release-8.0-0.1905.0.9.el8.x86_64                                                  5/5 
  Running scriptlet: centos-release-8.0-0.1905.0.9.el8.x86_64                                                  5/5 
  Verifying        : centos-gpg-keys-8.2-2.2004.0.2.el8.noarch                                                 1/5 
  Verifying        : centos-repos-8.2-2.2004.0.2.el8.x86_64                                                    2/5 
  Verifying        : remi-release-8.1-2.el8.remi.noarch                                                        3/5 
  Verifying        : centos-release-8.2-2.2004.0.2.el8.x86_64                                                  4/5 
  Verifying        : centos-release-8.0-0.1905.0.9.el8.x86_64                                                  5/5 

Upgraded:
  centos-release-8.2-2.2004.0.2.el8.x86_64                                                                         

Installed:
  remi-release-8.1-2.el8.remi.noarch                     centos-gpg-keys-8.2-2.2004.0.2.el8.noarch                
  centos-repos-8.2-2.2004.0.2.el8.x86_64                

Complete!

安装Remi存储库rpm后,列出可用的PHP模块流。

dnf module list php

您应该看到以下输出。

CentOS-8 - AppStream
Name              Stream                Profiles                                Summary                            
php               7.2 [d]               common [d], devel, minimal              PHP scripting language             
php               7.3                   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             
php               remi-8.0              common [d], devel, minimal              PHP scripting language             

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

在CentOS 8 / RHEL 8上安装PHP 8.0

启用php:remi-8.0模块以安装PHP 8.0。

dnf module enable php:remi-8.0 -y

输出:

Dependencies resolved.
===================================================================================================================
 Package                    Arch                      Version                     Repository                  Size
===================================================================================================================
Enabling module streams:
 php                                                  remi-8.0                                                    

Transaction Summary
===================================================================================================================

Complete!

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

使用dnf命令在CentOS 8 / RHEL 8上安装PHP 8.0。

dnf install -y php php-cli php-common

在CentOS 8 / RHEL 8上安装PHP 7.x

如本文所示,启用php:remi-7.x模块以在系统上安装PHP7.x。

安装PHP-FPM

如果要在RHEL 8上设置LEMP堆栈,则可能要安装php-fpm。

dnf install -y php-fpm

安装PHP扩展

PHP扩展是已编译的库,可为您的代码提供特定的支持。

广告

要在代码上提供MySQL支持,可以安装php-mysqlnd软件包。

dnf install -y php-mysqlnd

现在,以下命令将列出已安装的MySQL扩展。

php -m | grep -i mysql

输出:

mysqli
mysqlnd
pdo_mysql

结论

就这样。 我希望您已经学会了如何在CentOS 8 / RHEL 8上安装PHP 8.0。请在评论部分中分享您的反馈。

Sidebar