如何在CentOS 7上安装PHP 7.x

3

无论我跟随什么教程,最终都会出现这个错误。这里有一个示例教程。

[jalal@goku ~]$ sudo yum install epel-release yum-utils
Package epel-release-7-11.noarch already installed and latest version
Package yum-utils-1.1.31-50.el7.noarch already installed and latest version
[jalal@goku ~]$ sudo yum install http://rpms.remirepo.net/enterprise/remi-release-7.rpm
Error: Nothing to do

系统规格如下:

$ uname -a
Linux goku.bu.edu 3.10.0-957.5.1.el7.x86_64 #1 SMP Fri Feb 1 14:54:57 UTC 2019 x86_64 x86_64 x86_64 GNU/Linux
$ lsb_release -a
LSB Version:    :core-4.1-amd64:core-4.1-noarch
Distributor ID: CentOS
Description:    CentOS Linux release 7.6.1810 (Core) 
Release:    7.6.1810
Codename:   Core

我该如何在CentOS 7上安装php 7.x呢?

如果我忽略这个问题并按照以下命令操作(即使我已经删除了php5.x),它仍然会安装php 5.x:

$ sudo yum-config-manager --enable remi-php73
[sudo] password for jalal: 
=============================== repo: remi-php73 ===============================
[remi-php73]
async = True
bandwidth = 0
base_persistdir = /var/lib/yum/repos/x86_64/7
baseurl = 
cache = 0
cachedir = /var/cache/yum/x86_64/7/remi-php73
check_config_file_age = True
compare_providers_priority = 80
cost = 1000
deltarpm_metadata_percentage = 100
deltarpm_percentage = 
enabled = 1
enablegroups = True
exclude = 
failovermethod = priority
ftp_disable_epsv = False
gpgcadir = /var/lib/yum/repos/x86_64/7/remi-php73/gpgcadir
gpgcakey = 
gpgcheck = True
gpgdir = /var/lib/yum/repos/x86_64/7/remi-php73/gpgdir
gpgkey = file:///etc/pki/rpm-gpg/RPM-GPG-KEY-remi
hdrdir = /var/cache/yum/x86_64/7/remi-php73/headers
http_caching = all
includepkgs = 
ip_resolve = 
keepalive = True
keepcache = False
mddownloadpolicy = sqlite
mdpolicy = group:small
mediaid = 
metadata_expire = 21600
metadata_expire_filter = read-only:present
metalink = 
minrate = 0
mirrorlist = http://cdn.remirepo.net/enterprise/7/php73/mirror
mirrorlist_expire = 86400
name = Remi's PHP 7.3 RPM repository for Enterprise Linux 7 - x86_64
old_base_cache_dir = 
password = 
persistdir = /var/lib/yum/repos/x86_64/7/remi-php73
pkgdir = /var/cache/yum/x86_64/7/remi-php73/packages
priority = 99
proxy = False
proxy_dict = 
proxy_password = 
proxy_username = 
repo_gpgcheck = False
retries = 10
skip_if_unavailable = False
ssl_check_cert_permissions = True
sslcacert = 
sslclientcert = 
sslclientkey = 
sslverify = True
throttle = 0
timeout = 30.0
ui_id = remi-php73
ui_repoid_vars = releasever,
   basearch
username = 

$ sudo yum install php php-common php-opcache php-mcrypt php-cli php-gd php-curl php-mysqlnd
Package php-mcrypt is obsoleted by php-pecl-mcrypt, trying to install php-pecl-mcrypt-1.0.2-2.el7.remi.7.3.x86_64 instead
Error: Package: php-pecl-mcrypt-1.0.2-2.el7.remi.7.3.x86_64 (remi-php73)
           Requires: php(api) = 20180731-64
           Installing: php-common-5.4.16-46.el7.x86_64 (base)
               php(api) = 20100412-64
           Available: php55w-common-5.5.38-1.w7.x86_64 (webtatic)
               php(api) = 20121113-64
           Available: php56w-common-5.6.39-1.w7.x86_64 (webtatic)
               php(api) = 20131106-64
           Available: php56w-common-5.6.40-1.w7.x86_64 (webtatic)
               php(api) = 20131106-64
           Available: php70w-common-7.0.33-1.w7.x86_64 (webtatic)
               php(api) = 20151012-64
           Available: php71u-common-7.1.25-1.ius.centos7.x86_64 (ius)
               php(api) = 20160303-64
           Available: php71u-common-7.1.25-2.ius.centos7.x86_64 (ius)
               php(api) = 20160303-64
           Available: php71u-common-7.1.26-1.ius.centos7.x86_64 (ius)
               php(api) = 20160303-64
           Available: php71w-common-7.1.25-1.w7.x86_64 (webtatic)
               php(api) = 20160303-64
           Available: php71w-common-7.1.26-1.w7.x86_64 (webtatic)
               php(api) = 20160303-64
           Available: php72u-common-7.2.13-1.ius.centos7.x86_64 (ius)
               php(api) = 20170718-64
           Available: php72u-common-7.2.13-2.ius.centos7.x86_64 (ius)
               php(api) = 20170718-64
           Available: php72u-common-7.2.14-1.ius.centos7.x86_64 (ius)
               php(api) = 20170718-64
           Available: php72w-common-7.2.13-1.w7.x86_64 (webtatic)
               php(api) = 20170718-64
           Available: php72w-common-7.2.14-1.w7.x86_64 (webtatic)
               php(api) = 20170718-64
Error: Package: php-pecl-mcrypt-1.0.2-2.el7.remi.7.3.x86_64 (remi-php73)
           Requires: php(zend-abi) = 20180731-64
           Installing: php-common-5.4.16-46.el7.x86_64 (base)
               php(zend-abi) = 20100525-64
           Available: php55w-common-5.5.38-1.w7.x86_64 (webtatic)
               php(zend-abi) = 20121212-64
           Available: php56w-common-5.6.39-1.w7.x86_64 (webtatic)
               php(zend-abi) = 20131226-64
           Available: php56w-common-5.6.40-1.w7.x86_64 (webtatic)
               php(zend-abi) = 20131226-64
           Available: php70w-common-7.0.33-1.w7.x86_64 (webtatic)
               php(zend-abi) = 20151012-64
           Available: php71u-common-7.1.25-1.ius.centos7.x86_64 (ius)
               php(zend-abi) = 20160303-64
           Available: php71u-common-7.1.25-2.ius.centos7.x86_64 (ius)
               php(zend-abi) = 20160303-64
           Available: php71u-common-7.1.26-1.ius.centos7.x86_64 (ius)
               php(zend-abi) = 20160303-64
           Available: php71w-common-7.1.25-1.w7.x86_64 (webtatic)
               php(zend-abi) = 20160303-64
           Available: php71w-common-7.1.26-1.w7.x86_64 (webtatic)
               php(zend-abi) = 20160303-64
           Available: php72u-common-7.2.13-1.ius.centos7.x86_64 (ius)
               php(zend-abi) = 20170718-64
           Available: php72u-common-7.2.13-2.ius.centos7.x86_64 (ius)
               php(zend-abi) = 20170718-64
           Available: php72u-common-7.2.14-1.ius.centos7.x86_64 (ius)
               php(zend-abi) = 20170718-64
           Available: php72w-common-7.2.13-1.w7.x86_64 (webtatic)
               php(zend-abi) = 20170718-64
           Available: php72w-common-7.2.14-1.w7.x86_64 (webtatic)
               php(zend-abi) = 20170718-64
Error: Package: php-opcache-7.3.2-1.el7.remi.x86_64 (remi-php73)
           Requires: php-common(x86-64) = 7.3.2-1.el7.remi
           Installing: php-common-5.4.16-46.el7.x86_64 (base)
               php-common(x86-64) = 5.4.16-46.el7
           Available: php55w-common-5.5.38-1.w7.x86_64 (webtatic)
               php-common(x86-64) = 5.5.38-1.w7
           Available: php56w-common-5.6.39-1.w7.x86_64 (webtatic)
               php-common(x86-64) = 5.6.39-1.w7
           Available: php56w-common-5.6.40-1.w7.x86_64 (webtatic)
               php-common(x86-64) = 5.6.40-1.w7
           Available: php70w-common-7.0.33-1.w7.x86_64 (webtatic)
               php-common(x86-64) = 7.0.33-1.w7
           Available: php71u-common-7.1.25-1.ius.centos7.x86_64 (ius)
               php-common(x86-64) = 7.1.25-1.ius.centos7
           Available: php71u-common-7.1.25-2.ius.centos7.x86_64 (ius)
               php-common(x86-64) = 7.1.25-2.ius.centos7
           Available: php71u-common-7.1.26-1.ius.centos7.x86_64 (ius)
               php-common(x86-64) = 7.1.26-1.ius.centos7
           Available: php71w-common-7.1.25-1.w7.x86_64 (webtatic)
               php-common(x86-64) = 7.1.25-1.w7
           Available: php71w-common-7.1.26-1.w7.x86_64 (webtatic)
               php-common(x86-64) = 7.1.26-1.w7
           Available: php72u-common-7.2.13-1.ius.centos7.x86_64 (ius)
               php-common(x86-64) = 7.2.13-1.ius.centos7
           Available: php72u-common-7.2.13-2.ius.centos7.x86_64 (ius)
               php-common(x86-64) = 7.2.13-2.ius.centos7
           Available: php72u-common-7.2.14-1.ius.centos7.x86_64 (ius)
               php-common(x86-64) = 7.2.14-1.ius.centos7
           Available: php72w-common-7.2.13-1.w7.x86_64 (webtatic)
               php-common(x86-64) = 7.2.13-1.w7
           Available: php72w-common-7.2.14-1.w7.x86_64 (webtatic)
               php-common(x86-64) = 7.2.14-1.w7
 You could try using --skip-broken to work around the problem
 You could try running: rpm -Va --nofiles --nodigest
$ sudo yum install --skip-broken php php-common php-opcache php-mcrypt php-cli php-gd php-curl php-mysqlnd
Package php-mcrypt is obsoleted by php-pecl-mcrypt, trying to install php-pecl-mcrypt-1.0.2-2.el7.remi.7.3.x86_64 instead

Packages skipped because of dependency problems:
    libmcrypt-2.5.8-13.el7.x86_64 from epel
    php-opcache-7.3.2-1.el7.remi.x86_64 from remi-php73
    php-pecl-mcrypt-1.0.2-2.el7.remi.7.3.x86_64 from remi-php73

===============================================================================================================================================
 Package                             Arch                       Version                                   Repository                      Size
===============================================================================================================================================
Installing:
 php                                 x86_64                     5.4.16-46.el7                             base                           1.4 M
 php-cli                             x86_64                     5.4.16-46.el7                             base                           2.7 M
 php-common                          x86_64                     5.4.16-46.el7                             base                           565 k
 php-gd                              x86_64                     5.4.16-46.el7                             base                           128 k
 php-mysqlnd                         x86_64                     5.4.16-46.el7                             base                           174 k
Installing for dependencies:
 php-pdo                             x86_64                     5.4.16-46.el7                             base                            99 k
Skipped (dependency problems):
 libmcrypt                           x86_64                     2.5.8-13.el7                              epel                            99 k
 php-opcache                         x86_64                     7.3.2-1.el7.remi                          remi-php73                     304 k
 php-pecl-mcrypt                     x86_64                     1.0.2-2.el7.remi.7.3                      remi-php73                      29 k

Transaction Summary
===============================================================================================================================================
Install                        5 Packages (+1 Dependent package)
Skipped (dependency problems)  3 Packages

Is this ok [y/d/N]: y
$ php -v
PHP 5.4.16 (cli) (built: Oct 30 2018 19:30:51) 
Copyright (c) 1997-2013 The PHP Group
Zend Engine v2.4.0, Copyright (c) 1998-2013 Zend Technologies

1
你能执行一下 yum update 吗? - Ataur Rahman
1
你有4个PHP提供者,分别是base、IUS、webtatic和remi...这可能会引起问题。禁用IUS和webtatic。还要检查“priority”插件。 - Remi Collet
1
是的,yum更新没有帮助。 - Mona Jalal
这个回答解决了你的问题吗?如何在shell中更改默认的PHP基础版本? - Paulo Boaventura
3个回答

0

0

首先,在Centos上获取PHP 7时,您不需要Remi存储库,但目前(就今天而言)获取PHP 7.3需要该存储库。

然而,如果您想要在Centos上安装PHP 7 EDIT 7.2(我现在推荐用于生产),则可以使用{{link1:epel存储库}}

首先检查您是否已安装了正确的存储库:

$ yum repolist | grep -e ius -e remi

如果你还没有安装其中的一个软件库,你需要先安装它。

之后,只需移除旧版本的PHP并安装PHP 7(从IUS获取7.2版本或从remi获取7.3版本)即可。

$ yum remove php* -y
$ yum install php72u

编辑

根据Remi的评论,我实际上没有注意到php72u实际上来自IUS!要从remi存储库获取PHP 7.3,您可以运行yum update或:

$ yum install php php-cli php-fpm php-mysqlnd php-zip php-devel php-gd php-mcrypt php-mbstring php-curl php-xml php-pear php-bcmath php-json

php72u不是来自EPEL!(它来自IUS,另一个第三方仓库,该仓库提供“一些”php版本) - Remi Collet
哦,你说得对。我甚至从未注意到这一点。EPEL仍然停留在5.4版本(不可思议)。现在正在编辑答案。 - Yes Barry

0

在 RHEL 7 服务器上安装 PHP 7.x 的步骤

1) 启用 EPEL,RHEL 7 Server 可选仓库并安装 remirepo rpm

Login to your RHEL 7 Server and run the beneath commands one after the another to enable EPEL repository, install remirepo and enable RHEL 7 Server optional repository

[root@user~]# rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
[root@user ~]# wget http://rpms.remirepo.net/enterprise/remi-release-7.rpm
[root@user ~]# rpm -Uvh remi-release-7.rpm epel-release-latest-7.noarch.rpm
[root@user ~]# subscription-manager repos --enable=rhel-7-server-optional-rpms

2) 配置 PHP 7.x 存储库

[root@user ~]# yum install yum-utils
[root@user ~]# yum-config-manager --enable remi-php72

3)安装PHP 7.2及其依赖项

[root@user ~]# yum install php php-common php-opcache php-mcrypt php-cli php-gd php-curl php-mysql -y

4) 验证 PHP 版本

[root@user ~]# php -v

请参考以下链接获取详细信息,它会为您提供逐步操作指南:

https://www.linuxtechi.com/install-php-7-centos-7-rhel-7-server/

谢谢


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接