如何在 CentOS 7 上安装 PHP 5.6?

如何在 CentOS 7 上安装 PHP 5.6?

我正在使用 CentOS 7、Nginx 1.12.2 。根据文章https://www.svnlabs.com/blogs/install-apache-mysql-php-5-6-on-centos-7/,我尝试

rpm -Uvh http://vault.centos.org/7.0.1406/extras/x86_64/Packages/epel-release-7-5.noarch.rpm

结果

[root@VMHostDefault ~]# yum --enablerepo=remi,remi-php56 install php php-common
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirrors.viethosting.com
 * epel: mirror.horizon.vn
 * extras: mirrors.viethosting.com
 * ius: hkg.mirror.rackspace.com
 * remi: ftp.riken.jp
 * remi-php56: ftp.riken.jp
 * remi-php73: ftp.riken.jp
 * remi-safe: ftp.riken.jp
 * updates: mirrors.viethosting.com
Package php-7.3.5-1.el7.remi.x86_64 already installed and latest version
Package php-common-7.3.5-1.el7.remi.x86_64 already installed and latest version
Nothing to do
[root@VMHostDefault ~]# rpm -Uvh http://vault.centos.org/7.0.1406/extras/x86_64/Packages/epel-release-7-5.noarch.rpm
Retrieving http://vault.centos.org/7.0.1406/extras/x86_64/Packages/epel-release-7-5.noarch.rpm
Preparing...                          ################################# [100%]
    package epel-release-7-11.noarch (which is newer than epel-release-7-5.noarch) is already installed
[root@VMHostDefault ~]# 

然后

rpm -Uvh http://rpms.famillecollet.com/enterprise/remi-release-7.rpm

结果

[root@VMHostDefault ~]# rpm -Uvh http://rpms.famillecollet.com/enterprise/remi-release-7.rpm
Retrieving http://rpms.famillecollet.com/enterprise/remi-release-7.rpm
Preparing...                          ################################# [100%]
    package remi-release-7.6-2.el7.remi.noarch is already installed

yum --enablerepo=remi,remi-php56 install php php-common

结果

[root@VMHostDefault ~]# yum --enablerepo=remi,remi-php56 install php php-common
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirrors.viethosting.com
 * epel: mirror.horizon.vn
 * extras: mirrors.viethosting.com
 * ius: hkg.mirror.rackspace.com
 * remi: ftp.riken.jp
 * remi-php56: ftp.riken.jp
 * remi-php73: ftp.riken.jp
 * remi-safe: ftp.riken.jp
 * updates: mirrors.viethosting.com
Package php-7.3.5-1.el7.remi.x86_64 already installed and latest version
Package php-common-7.3.5-1.el7.remi.x86_64 already installed and latest version
Nothing to do


[root@VMHostDefault ~]# yum --enablerepo=remi,remi-php56 install php-cli php-pear php-pdo php-mysql php-mysqlnd php-pgsql php-sqlite php-gd php-mbstring php-mcrypt php-xml php-simplexml php-curl php-zip
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirrors.viethosting.com
 * epel: mirror.horizon.vn
 * extras: mirrors.viethosting.com
 * ius: hkg.mirror.rackspace.com
 * remi: ftp.riken.jp
 * remi-php56: ftp.riken.jp
 * remi-php73: ftp.riken.jp
 * remi-safe: ftp.riken.jp
 * updates: mirrors.viethosting.com
Package php-cli-7.3.5-1.el7.remi.x86_64 already installed and latest version
Package php-mysql is obsoleted by php-mysqlnd, trying to install php-mysqlnd-7.3.5-1.el7.remi.x86_64 instead
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
Package php-common-7.3.5-1.el7.remi.x86_64 already installed and latest version
Resolving Dependencies
--> Running transaction check
---> Package php-gd.x86_64 0:7.3.5-1.el7.remi will be installed
---> Package php-mbstring.x86_64 0:7.3.5-1.el7.remi will be installed
---> Package php-mysqlnd.x86_64 0:7.3.5-1.el7.remi will be installed
---> Package php-pdo.x86_64 0:7.3.5-1.el7.remi will be installed
---> Package php-pear.noarch 1:1.10.9-2.el7.remi will be installed
--> Processing Dependency: php-composer(fedora/autoloader) for package: 1:php-pear-1.10.9-2.el7.remi.noarch
--> Processing Dependency: php-posix for package: 1:php-pear-1.10.9-2.el7.remi.noarch
---> Package php-pecl-mcrypt.x86_64 0:1.0.2-2.el7.remi.7.3 will be installed
---> Package php-pecl-sqlite.x86_64 0:2.0.0-0.7.svn332053.el7.remi.5.6 will be installed
--> Processing Dependency: php(api) = 20131106-64 for package: php-pecl-sqlite-2.0.0-0.7.svn332053.el7.remi.5.6.x86_64
--> Processing Dependency: php(zend-abi) = 20131226-64 for package: php-pecl-sqlite-2.0.0-0.7.svn332053.el7.remi.5.6.x86_64
--> Processing Dependency: libsqlite.so.0()(64bit) for package: php-pecl-sqlite-2.0.0-0.7.svn332053.el7.remi.5.6.x86_64
---> Package php-pecl-zip.x86_64 0:1.15.4-1.el7.remi.7.3 will be installed
---> Package php-pgsql.x86_64 0:7.3.5-1.el7.remi will be installed
---> Package php-xml.x86_64 0:7.3.5-1.el7.remi will be installed
--> Running transaction check
---> Package php-fedora-autoloader.noarch 0:1.0.0-1.el7.remi will be installed
---> Package php-pecl-sqlite.x86_64 0:2.0.0-0.7.svn332053.el7.remi.5.6 will be installed
--> Processing Dependency: php(api) = 20131106-64 for package: php-pecl-sqlite-2.0.0-0.7.svn332053.el7.remi.5.6.x86_64
--> Processing Dependency: php(zend-abi) = 20131226-64 for package: php-pecl-sqlite-2.0.0-0.7.svn332053.el7.remi.5.6.x86_64
---> Package php-process.x86_64 0:7.3.5-1.el7.remi will be installed
---> Package sqlite2.x86_64 0:2.8.17-17.el7 will be installed
--> Finished Dependency Resolution
Error: Package: php-pecl-sqlite-2.0.0-0.7.svn332053.el7.remi.5.6.x86_64 (remi-php56)
           Requires: php(zend-abi) = 20131226-64
           Installed: php-common-7.3.5-1.el7.remi.x86_64 (@remi-php73)
               php(zend-abi) = 20180731-64
           Available: php-common-5.4.16-46.el7.x86_64 (base)
               php(zend-abi) = 20100525-64
           Available: php-common-5.4.45-16.el7.remi.x86_64 (remi)
               php(zend-abi) = 20100525-64
           Available: php-common-5.4.45-17.el7.remi.x86_64 (remi)
               php(zend-abi) = 20100525-64
           Available: php-common-5.6.40-7.el7.remi.x86_64 (remi-php56)
               php(zend-abi) = 20131226-64
           Available: php-common-5.6.40-8.el7.remi.x86_64 (remi-php56)
               php(zend-abi) = 20131226-64
           Available: php-common-7.3.4-1.el7.remi.x86_64 (remi-php73)
               php(zend-abi) = 20180731-64
           Available: php71u-common-7.1.26-1.ius.centos7.x86_64 (ius)
               php(zend-abi) = 20160303-64
           Available: php71u-common-7.1.27-1.ius.centos7.x86_64 (ius)
               php(zend-abi) = 20160303-64
           Available: php71u-common-7.1.28-1.ius.centos7.x86_64 (ius)
               php(zend-abi) = 20160303-64
           Available: php72u-common-7.2.15-1.ius.centos7.x86_64 (ius)
               php(zend-abi) = 20170718-64
           Available: php72u-common-7.2.16-1.ius.centos7.x86_64 (ius)
               php(zend-abi) = 20170718-64
           Available: php72u-common-7.2.17-1.ius.centos7.x86_64 (ius)
               php(zend-abi) = 20170718-64
Error: Package: php-pecl-sqlite-2.0.0-0.7.svn332053.el7.remi.5.6.x86_64 (remi-php56)
           Requires: php(api) = 20131106-64
           Installed: php-common-7.3.5-1.el7.remi.x86_64 (@remi-php73)
               php(api) = 20180731-64
           Available: php-common-5.4.16-46.el7.x86_64 (base)
               php(api) = 20100412-64
           Available: php-common-5.4.45-16.el7.remi.x86_64 (remi)
               php(api) = 20100412-64
           Available: php-common-5.4.45-17.el7.remi.x86_64 (remi)
               php(api) = 20100412-64
           Available: php-common-5.6.40-7.el7.remi.x86_64 (remi-php56)
               php(api) = 20131106-64
           Available: php-common-5.6.40-8.el7.remi.x86_64 (remi-php56)
               php(api) = 20131106-64
           Available: php-common-7.3.4-1.el7.remi.x86_64 (remi-php73)
               php(api) = 20180731-64
           Available: php71u-common-7.1.26-1.ius.centos7.x86_64 (ius)
               php(api) = 20160303-64
           Available: php71u-common-7.1.27-1.ius.centos7.x86_64 (ius)
               php(api) = 20160303-64
           Available: php71u-common-7.1.28-1.ius.centos7.x86_64 (ius)
               php(api) = 20160303-64
           Available: php72u-common-7.2.15-1.ius.centos7.x86_64 (ius)
               php(api) = 20170718-64
           Available: php72u-common-7.2.16-1.ius.centos7.x86_64 (ius)
               php(api) = 20170718-64
           Available: php72u-common-7.2.17-1.ius.centos7.x86_64 (ius)
               php(api) = 20170718-64
 You could try using --skip-broken to work around the problem
 You could try running: rpm -Va --nofiles --nodigest
[root@VMHostDefault ~]# 

然后检查PHP版本

[root@VMHostDefault ~]# php -v
PHP 7.3.5 (cli) (built: Apr 30 2019 08:37:17) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.3.5, Copyright (c) 1998-2018 Zend Technologies

我无法安装 PHP 5.6(我需要 5.6 版本,因为旧网页需要该版本)。我需要在 CentOS 7 上安装 PHP 5.6。

答案1

做这些

yum-config-manager --disable remi-php73
yum-config-manager --disable remi-php72
yum-config-manager --disable remi-php71
yum-config-manager --disable remi-php70
yum -y remove php*
rm -r remi-php54.repo 
rm -r remi-php7*
yum install https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
yum install http://rpms.remirepo.net/enterprise/remi-release-7.rpm
yum install yum-utils
yum-config-manager --enable remi-php56
yum install php56
php56 -v

相关内容