在 CentOS 6.5 上升级 PHP(最终版)
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/21502656/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Upgrading PHP on CentOS 6.5 (Final)
提问by BCLtd
I'm trying to update my PHP (currently v:5.3.3 to the latest stable PHP build) but it's not playing ball and it's saying there is nothing to update.
我正在尝试更新我的 PHP(当前 v:5.3.3 到最新的稳定 PHP 版本),但它没有正常运行,并且说没有什么可更新的。
Any help would be useful.
任何帮助都会有用。
Keeps saying:
一直说:
No Packages marked for Update
没有包标记为更新
回答by Simon East
As Jacob mentioned, the CentOS packages repo appears to only have PHP 5.3 available at the moment. But these commands seemed to work for me...
正如雅各布所说,CentOS 软件包存储库目前似乎只有 PHP 5.3 可用。但是这些命令似乎对我有用......
rpm -Uvh http://mirror.webtatic.com/yum/el6/latest.rpm
yum remove php-common # Need to remove this, otherwise it conflicts
yum install php56w
yum install php56w-mysql
yum install php56w-common
yum install php56w-pdo
yum install php56w-opcache
php --version # Verify version has been upgraded
You can alternatively use php54wor php55wif required.
如果需要,您也可以使用php54w或php55w。
CAUTION!
This may potentially break your website if it doesn't fully resolve all your dependencies, so you may need a couple of extra packages in some cases. See herefor a list of other PHP 5.6 modules that are available.
警告!
如果它不能完全解决您的所有依赖项,这可能会破坏您的网站,因此在某些情况下您可能需要几个额外的包。有关可用的其他 PHP 5.6 模块的列表,请参见此处。
If you encounter a problem and need to reset back to the default, you can use these commands:
如果遇到问题需要重置回默认值,可以使用以下命令:
sudo yum remove php56w
sudo yum remove php56w-common
sudo yum install php-common
sudo yum install php-mysql
sudo yum install php
(Thanks Fabrizio Bartolomucci)
(感谢法布里齐奥·巴托洛穆奇)
回答by Jacob Budin
For CentOS 6, PHP 5.3.3 is the latest version of PHP available through the official CentOS package repository. Keep in mind, even though PHP 5.3.3 was released July 22, 2010, the official CentOS 6 PHP package was updated November 24, 2013. Why? Critical bug fixes are backported. See this question for more information: "Why are outdated packages installed by yum on CentOS? (specifically PHP 5.1) How to fix?"
对于 CentOS 6,PHP 5.3.3 是最新版本的 PHP,可通过官方 CentOS 软件包存储库获得。请记住,尽管PHP 5.3.3 已于 2010 年 7 月 22 日发布,但 CentOS 6 PHP 官方软件包已于 2013 年 11 月 24 日更新。为什么?关键的错误修复被反向移植。有关更多信息,请参阅此问题:“为什么 yum 在 CentOS 上安装了过时的软件包?(特别是 PHP 5.1)如何修复?”
If you'd like to use a more recent version of PHP, Les RPM de Remioffers CentOS PHP packages via a repository that you can add to the yum package manager. To add it as a yum repository, follow the site's instructions.
如果您想使用更新版本的 PHP,Les RPM de Remi通过一个存储库提供 CentOS PHP 软件包,您可以将其添加到 yum 软件包管理器。要将其添加为 yum 存储库,请按照站点的说明进行操作。
Note: Questions of this variety are probably better suited for Server Fault.
注意:这种类型的问题可能更适合Server Fault。
回答by Jacob Budin
I managed to install php54w according to Simon's suggestion, but then my sites stopped working perhaps because of an incompatibility with php-mysql or some other module. Even frantically restoring the old situation was not amusing: for anyone in my own situation the sequence is:
我根据 Simon 的建议设法安装了 php54w,但随后我的网站停止工作,可能是因为与 php-mysql 或其他一些模块不兼容。即使疯狂地恢复旧的情况也并不有趣:对于我自己情况的任何人来说,顺序是:
sudo yum remove php54w
sudo yum remove php54w-common
sudo yum install php-common
sudo yum install php-mysql
sudo yum install php
It would be nice if someone submitted the full procedure to update all the php packet. That was my production server and my heart is still rapidly beating.
如果有人提交更新所有 php 数据包的完整程序,那就太好了。那是我的生产服务器,我的心仍在快速跳动。
回答by Bonfix Ngetich
This is the easiest way that worked for me: To install PHP 5.6 on CentOS 6 or 7:
这是对我有用的最简单的方法:在 CentOS 6 或 7 上安装 PHP 5.6:
CentOS 6. Enter the following commands in the order shown:
CentOS 6. 按所示顺序输入以下命令:
yum -y update
yum -y install epel-release
wget https://dl.fedoraproject.org/pub/epel/epel-release-latest-6.noarch.rpm
wget https://centos6.iuscommunity.org/ius-release.rpm
rpm -Uvh ius-release*.rpm
yum -y update
yum -y install php56u php56u-opcache php56u-xml php56u-mcrypt php56u-gd php56u-devel php56u-mysql php56u-intl php56u-mbstring php56u-bcmath
CentOS 7. Enter the following commands in the order shown:
CentOS 7. 按所示顺序输入以下命令:
yum -y update
yum -y install epel-release
wget https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
wget https://centos7.iuscommunity.org/ius-release.rpm
rpm -Uvh ius-release*.rpm
yum -y update
yum -y install php56u php56u-opcache php56u-xml php56u-mcrypt php56u-gd php56u-devel php56u-mysql php56u-intl php56u-mbstring php56u-bcmath
Sorry - I'm unable to post the source URL - due to reputation
抱歉 - 由于声誉原因,我无法发布源 URL
回答by Fouad Djebbar
Verify current version of PHP Type in the following to see the current PHP version:
php -v
Should output something like:
PHP 5.3.3 (cli) (built: Jul 9 2015 17:39:00) Copyright (c) 1997-2010 The PHP Group Zend Engine v2.3.0, Copyright (c) 1998-2010 Zend Technologies
Install the Remi and EPEL RPM repositories
验证当前版本的 PHP 键入以下内容以查看当前的 PHP 版本:
php -v
应该输出类似:
PHP 5.3.3 (cli)(构建时间:2015 年 7 月 9 日 17:39:00) 版权所有 (c) 1997-2010 PHP Group Zend Engine v2.3.0,版权所有 (c) 1998-2010 Zend Technologies
安装 Remi 和 EPEL RPM 存储库
If you haven't already done so, install the Remi and EPEL repositories
如果您还没有这样做,请安装 Remi 和 EPEL 存储库
wget https://dl.fedoraproject.org/pub/epel/epel-release-latest-6.noarch.rpm && rpm -Uvh epel-release-latest-6.noarch.rpm
wget http://rpms.famillecollet.com/enterprise/remi-release-6.rpm && rpm -Uvh remi-release-6*.rpm
Enable the REMI repository globally:
全局启用 REMI 存储库:
nano /etc/yum.repos.d/remi.repo
Under the section that looks like [remi] make the following changes:
在看起来像 [remi] 的部分下进行以下更改:
[remi]
name=Remi's RPM repository for Enterprise Linux 6 - $basearch
#baseurl=http://rpms.remirepo.net/enterprise/6/remi/$basearch/
mirrorlist=http://rpms.remirepo.net/enterprise/6/remi/mirror
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-remi
Also, under the section that looks like [remi-php55] make the following changes:
此外,在看起来像 [remi-php55] 的部分下进行以下更改:
[remi-php56]
name=Remi's PHP 5.6 RPM repository for Enterprise Linux 6 - $basearch
#baseurl=http://rpms.remirepo.net/enterprise/6/php56/$basearch/
mirrorlist=http://rpms.remirepo.net/enterprise/6/php56/mirror
# WARNING: If you enable this repository, you must also enable "remi"
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-remi
Type CTRL-O to save and CTRL-X to close the editor
输入 CTRL-O 保存,输入 CTRL-X 关闭编辑器
Upgrade PHP 5.3 to PHP 5.6 Now we can upgrade PHP. Simply type in the following command:
yum -y upgrade php*
将 PHP 5.3 升级到 PHP 5.6 现在我们可以升级 PHP。只需输入以下命令:
yum -y 升级 php*
Once the update has completed, let's verify that you have PHP 5.6 installed:
更新完成后,让我们验证您是否安装了 PHP 5.6:
php -v
Should see output similar to the following:
应该会看到类似于以下内容的输出:
PHP 5.6.14 (cli) (built: Sep 30 2015 14:07:43)
Copyright (c) 1997-2015 The PHP Group
Zend Engine v2.6.0, Copyright (c) 1998-2015 Zend Technologies
回答by SyntaxGoonoo
Steps for upgrading to PHP7 on CentOS 6 system. Taken from install-php-7-in-centos-6
CentOS 6系统升级到PHP7的步骤。取自install-php-7-in-centos-6
To install latest PHP 7, you need to add EPEL and Remi repository to your CentOS 6 system
要安装最新的 PHP 7,您需要将 EPEL 和 Remi 存储库添加到您的 CentOS 6 系统
yum install https://dl.fedoraproject.org/pub/epel/epel-release-latest-6.noarch.rpm
yum install http://rpms.remirepo.net/enterprise/remi-release-6.rpm
Now install yum-utils, a group of useful tools that enhance yum's default package management features
现在安装 yum-utils,一组增强 yum 默认包管理功能的有用工具
yum install yum-utils
In this step, you need to enable Remi repository using yum-config-manager utility, as the default repository for installing PHP.
在这一步中,您需要使用 yum-config-manager 实用程序启用 Remi 存储库,作为安装 PHP 的默认存储库。
yum-config-manager --enable remi-php70
If you want to install PHP 7.1 or PHP 7.2 on CentOS 6, just enable it as shown.
如果您想在 CentOS 6 上安装 PHP 7.1 或 PHP 7.2,只需如图所示启用它。
yum-config-manager --enable remi-php71
yum-config-manager --enable remi-php72
Then finally install PHP 7 on CentOS 6 with all necessary PHP modules using the following command.
然后最后使用以下命令在 CentOS 6 上安装 PHP 7 和所有必需的 PHP 模块。
yum install php php-mcrypt php-cli php-gd php-curl php-mysql php-ldap php-zip php-fileinfo
Double check the installed version of PHP on your system as follows.
仔细检查系统上已安装的 PHP 版本,如下所示。
php -V
回答by Arvind Kumar Rawat
IUS offers an installation script for subscribing to their repository and importing associated GPG keys. Make sure you're in your home directory, and retrieve the script using curl:
IUS 提供了一个安装脚本,用于订阅其存储库并导入相关的 GPG 密钥。确保您位于主目录中,并使用 curl 检索脚本:
curl 'https://setup.ius.io/' -o setup-ius.sh
sudo bash setup-ius.sh
Install Required Packages-:
安装所需的软件包-:
sudo yum install -y mod_php70u php70u-cli php70u-mysqlnd php70u-json php70u-gd php70u-dom php70u-simplexml php70u-mcrypt php70u-intl

