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

时间:2019-02-10 01:02:40

标签: php installation centos

无论我遵循什么教程,最终都会遇到此错误。这是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

3 个答案:

答案 0 :(得分:0)

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

但是,如果您要安装 PHP 7 您可以在 epel repository 上在Centos上进行 EDIT 7.2(我建议立即用于生产):

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

$ 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

答案 1 :(得分:0)


在centos 7中安装PHP版本


7.1

7.2

7.3

7.4 或扩展名

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

答案 2 :(得分:-1)

RHEL 7 Server上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/

谢谢