【问题标题】:How to install php 7.x on CentOS 7如何在 CentOS 7 上安装 php 7.x
【发布时间】:2019-07-03 21:00:53
【问题描述】:

无论我遵循什么教程,我都会遇到这个错误。这是example tutorial.

[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

【问题讨论】:

  • 你能做一个yum update吗?
  • 1/ 您有 4 个 PHP、base、IUS、webtatic 和 remi 提供程序。这只会引发问题。禁用 IUS 和 webtatic。还要检查“优先”插件。
  • 是的,yum 更新没有帮助

标签: php installation centos


【解决方案1】:

首先,您不需要 Centos 上的 Remi 存储库来获取 PHP 7,但目前(就像今天一样)您确实需要它用于 PHP 7.3。

但是,如果您想安装 PHP 7 在 Centos 上编辑 7.2(我现在推荐用于生产),您可以使用 epel repository

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

$ 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,另一个 3rd 方 repo,它提供“一些”php 版本)
  • 天哪,你是对的。我什至从未注意到这一点。 EPEL 仍为 5.4(虚幻)。立即编辑答案
【解决方案2】:

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

1) 启用 EPEL、RHEL 7 服务器可选存储库并安装 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/

谢谢

【讨论】:

    【解决方案3】:

    在centos 7中安装PHP版本


    7.1

    7.2

    7.3

    7.4 或扩展

    How do I change the default PHP base-version on shell?

    【讨论】:

      猜你喜欢
      • 2017-10-06
      • 1970-01-01
      • 2019-06-22
      • 1970-01-01
      • 1970-01-01
      • 2017-12-05
      • 1970-01-01
      • 2018-11-13
      • 2018-05-28
      相关资源
      最近更新 更多