默认情况下,CentOS/RHEL6操作系统在其官方存储库中提供PHP5.3,CentOS/RHEL7提供PHP5.4。在本文中,我们将向您展示如何在CentOS/RHEL7和CentOS/RHEL6系统上安装最新版本的PHP。这可以通过向系统添加必要的额外第三方RPM存储库来完成。方法一:如何使用软件集合库(SCL)在CentOS6/7上安装PHP7现在,SCL库由CentOSSIG维护,它不仅重建了RedHatSoftwareCollections,还提供了一些其他包。它包含各种程序的更新版本,这些程序可以与现有的遗留包一起安装并使用scl命令调用。要在CentOS上安装软件集合存储库(SCL),请运行以下yum命令#yuminstallcentos-release-scl运行以下命令以验证SCL存储库中可用的PHP7版本:#yum--disablerepo="*"--enablerepo="centos-sclo-rh"list*phpLoadedplugins:fastestmirror,langpacksLoadingmirrorspeedsfromcachedhostfilecentos-sclo-rh:centos.mirrors.estointernet.inAvailablePackagesphp54-php.x86_645.4.40-4.el7centos-sclo-rhphp55-php.x86_645。5.el7centos-sclo-rhrh-php70-php.x86_647.0.27-2.el7centos-sclo-rhrh-php71-php.x86_647.1.30-2.el7centos-sclo-rhrh-php72-php.x86_647.2.24-1。el7centos-sclo-rh运行以下命令将PHP7.2从SCL安装到您的系统:#yum--disablerepo="*"--enablerepo="centos-sclo-rh"installrh-php72-php如果需要PHP7.2安装其他模块,您可以通过运行以下命令格式来安装它们。例如,您可以通过执行以下命令来安装gd和pdo软件包:#yum--disablerepo="*"--enablerepo="centos-sclo-rh"installrh-php72-php-gdrh-php72-php-pdo方法-1a:如何使用软件集合存储库(SCL)在RHEL7上安装PHP7对于RedHat7,启用以下存储库以安装最新的PHP7软件包:#sudosubscription-managerrepos--enablerhel-7-server-extras-rpms#sudosubscription-managerrepos--enablerhel-7-server-optional-rpms#sudosubscription-managerrepos--enablerhel-server-rhscl-7-rpms运行以下命令从RHSCL存储库中搜索可用的PHP7版本:#yumsearchrh-php*您可以通过运行以下命令轻松地从RHEL7计算机上的RHSCL存储库安装PHP7.3:#yuminstallrh-php73方法2:如何使用Remi存储库在CentOS6/7上安装PHP7Remi存储库存储和维护最新版本的PHP包,其中包含大量的库,ext感知和工具。有些是从Fedora和EPEL向后移植的。这是CentOS社区批准的存储库,它不会修改或影响任何底层组件。作为先决条件,如果您的系统上尚未安装EPEL存储库,这将首先安装它。您可以轻松地从Remi存储库中找到可用的PHP7包版本,因为它为每个版本添加了一个单独的存储库。您可以使用ls命令查看它们:#ls-lh/etc/yum.repos.d/remi-php*-rw-r--r--.1rootroot456Sep601:31/etc/yum.repos.d/remi-php54.repo-rw-r--r--.1rootroot1.3KSep601:31/etc/yum.repos.d/remi-php70.repo-rw-r--r--.1rootroot1.3KSep601:31/etc/yum.repos.d/remi-php71.repo-rw-r--r--.1rootroot1.3KSep601:31/etc/yum.repos.d/remi-php72.repo-rw-r--r--。1rootroot1.3KSep601:31/etc/yum.repos.d/remi-php73.repo-rw-r--r--.1rootroot1.3KSep601:31/etc/yum.repos.d/remi-php74.repo运行以下命令,您可以轻松地从Remi存储库在您的CentOS6/7机器上安装PHP7.4:#yum--disablerepo="*"--enablerepo="remi-php74"installphpphp-mcryptphp-cliphp-gdphp-curlphp-mysqlphp-ldapphp-zipphp-fileinfo方法2a:如何使用Remi存储库在RHEL7上安装PHP7对于RedHat7,安装以下存储库以安装最新的PHP7软件包。在RHEL7上安装EPEL存储库:#yuminstallhttps://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm在RHEL7上安装Remi存储库:#yuminstallhttp://rpms.remirepo.net/enterprise/remi-release-7.rpm启用可选的RPMS存储库:#subscription-managerrepos--enable=rhel-7-server-optional-rpms运行以下命令即可轻松从remi存储库下载,安装PHP7.4到RHEL7系统:#yum--disablerepo="*"--enablerepo="remi-php74"installphpphp-mcryptphp-cliphp-gdphp-curlphp-mysqlphp-ldapphp-zipphp-fileinfo要验证PHP7安装版本,请运行以下命令命令:#php-vPHP7.4.1(cli)(built:Dec17201916:35:58)(NTS)Copyright(c)ThePHPGroupZendEnginev3.4.0,Copyright(c)ZendTechnologiesMethod-3:HowtouseIUSCommunityRepositoryInstallingPHPonCentOS6/77TheIUSCommunityRepository是CentOS社区认可的第三方RPM仓库,包含PHP、Python、MySQL和Lin等软件的最新上游版本用于企业Linux(RHEL和CentOS)5、6和7软件包的ux。IUS社区仓库与EPEL仓库有依赖关系,所以我们必须先安装EPEL仓库,然后再安装IUS仓库。在安装软件包之前,请按照以下步骤将EPEL和IUS社区存储库安装并启用到您的RPM系统。EPEL包包含在CentOSExtras仓库中,默认是启用的,所以我们可以通过运行以下命令来安装它:#yuminstallel-release下载IUS社区仓库的shell脚本如下:#curl'https://设置。ius.io/'-osetup-ius.sh%Total%Received%XferdAverageSpeedTimeTimeTimeTimeCurrentDloadUploadTotalSpentLeftSpeed100191410019140065630--:--:----:--:----:--:--13安装/启用IUS社区存储库:#shsetup-ius.sh运行以下命令检查IUS存储库中可用的PHP7版本:#yum--disablerepo="*"--enablerepo="ius"list*php7*Loadedplugins:fastestmirror,langpacksLoadingmirrorspeedsfromcachedhostfileAvailablePackagesmod_php71u.x86_647。1.33-1.el7.iusiusmod_php72u.x86_647.2.26-1.el7.iusiusmod_php73.x86_647.3.13-1.el7.iusiusphp71u-bcmath.x86_647.1.33-1.el7.iusiusphp71u-cli.x86_647.1.33-1.el7。iusius-common.x86_647.1.33-1.el7.iusiusphp71u-dba.x86_647.1.33-1.el7.iusiusphp71u-dbg.x86_647.1.33-1.el7.iusiusphp71u-devel.x86_647.1.33-1.el7.iusiusphp71u-嵌入式.x86_647.1.33-1.el7.iusius您可以通过运行以下命令从CentOS6/7系统上的IUS存储库轻松安装PHP7.3:#yum--disablerepo="*"--enablerepo="ius"installphp73-commonphp73-cliphp73-gdphp73-gdphp73-mysqlndphp73-ldapphp73-soapphp73-mbstring
