我可以从 PHP 5.3.10 迁移到 PHP 5.6.0 吗?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/25579736/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 17:54:03  来源:igfitidea点击:

Can I migrate from PHP 5.3.10 to PHP 5.6.0?

phpphp-5.3portingphp-5.6

提问by PHPFan

I'm basically a PHPdeveloper. I'm currently using Ubuntu Linux 12.04 LTSon my local machine.

我基本上是一名PHP开发人员。我目前在本地机器上使用Ubuntu Linux 12.04 LTS

I'm using the following PHPversion for developing my PHPproject:

我正在使用以下PHP版本来开发我的PHP项目:

php -v //command run at terminal to know the `PHP` version installed

PHP 5.3.10-1ubuntu3.13 with Suhosin-Patch (cli) (built: Jul  7 2014 18:54:55) 
Copyright (c) 1997-2012 The PHP Group
Zend Engine v2.3.0, Copyright (c) 1998-2012 Zend Technologies

Now a couple of days back a new latest stable release of PHPversion (PHP 5.6.0) was released by the PHPdevelopment team.

几天前,开发团队发布了PHP版本 ( PHP 5.6.0) 的最新稳定版本PHP

My question is, as I'm using a PHPversion on my local machine which is too old, and also all PHPversions lower than 5.4are officially unsupported or announced end-of-life, should I go for PHP 5.6.0?

我的问题是,由于我在PHP本地机器上使用的版本太旧,而且所有PHP版本都低于5.4官方不支持或宣布停产的版本,我应该去PHP 5.6.0吗?

If your answer is yes, please explain me how to do it? Will the code I written in my project work properly after this migration? What changes I'll need to do?

如果您的回答是肯定的,请解释我该怎么做?这次迁移后,我在项目中编写的代码是否可以正常工作?我需要做哪些改变?

If your answer is no, please explain me in detail why?

如果您的回答是否定的,请详细解释为什么?

Before asking this question I've gone through Googleand PHPdocumentation. There I found migration notes for following version migrations:

在问这个问题之前,我已经浏览了谷歌PHP文档。在那里我找到了以下版本迁移的迁移说明:

   **5.3.x->5.4.x
   5.4.x->5.5.x
   5.5.x->5.6.x**

Didn't get how to migrate from PHP 5.3.10to PHP 5.6.0.

不知道如何从 迁移PHP 5.3.10PHP 5.6.0.

So can someone please help me in this regard?

那么有人可以在这方面帮助我吗?

If you need any further information regarding my issue please do let me know.

如果您需要有关我的问题的任何进一步信息,请告诉我。

回答by DevilishDB

TL;DR PHP 5.3.x will still get security upgrades by Ubuntu but upgrade to 14.04.1 for a newer version

TL; DR PHP 5.3.x 仍将获得 Ubuntu 的安全升级,但升级到 14.04.1 以获得更新版本

You could download and build/install the source for PHP 5.6 from the website, but don't, since it means you risk losing stability with your system because other packages on your system won't be designed for this version and you'll have to upgrade it manually every time a new version comes out, risking stability if those upgrades are security-related since you won't get them upgraded quickly like you would using a package manager.

您可以从网站下载并构建/安装 PHP 5.6 的源代码,但不要这样做,因为这意味着您可能会失去系统稳定性,因为您系统上的其他软件包不是为此版本设计的,您将拥有每次出现新版本时手动升级它,如果这些升级与安全相关,则可能会冒着稳定性的风险,因为您不会像使用包管理器那样快速升级它们。

Instead, I suggest you upgrade your distribution to Ubuntu 14.04.1, which contains PHP 5.5.9; a lot newer than 5.3.10. Of course, 5.3.x will still receive security updates until Ubuntu 12.04 reaches EOL but if you want the latest features you should dist-upgrade. You can do this graphically in the Ubuntu software updater or run apt-get dist-upgradeas root (e.g with sudo) in the TTY if you're using the server version. Update: use sudo do-release-upgradeinstead.

相反,我建议您将发行版升级到 Ubuntu 14.04.1,其中包含 PHP 5.5.9;比 5.3.10 新很多。当然,在 Ubuntu 12.04 达到 EOL 之前,5.3.x 仍会收到安全更新,但是如果您想要最新的功能,则应该进行 dist-upgrade。如果您使用的是服务器版本,您可以在 Ubuntu 软件更新程序中以图形方式执行此操作,或者在 TTY 中apt-get dist-upgrade以 root 身份运行(例如使用sudo)。更新:sudo do-release-upgrade改为使用。

Edit: Just to clarify, apt-get is the package manager. If you usually use graphical tools to install and update packages (ubuntu software center, synaptic, etc.), here are some simple commands. #indicates that it must be ran as root (e.g. sudo apt-get install <package>), $indicates you don't need sudo. Replace things in with the thing you want to use (e.g. apt-get install chromium-browser)

编辑:澄清一下,apt-get 是包管理器。如果你平时使用图形工具来安装和更新包(ubuntu软件中心、synaptic等),这里有一些简单的命令。#表示它必须以 root 身份运行(例如sudo apt-get install <package>),$表示您不需要sudo. 用你想要使用的东西替换东西(例如apt-get install chromium-browser

#apt-get updateupdates the repositories
#apt-get upgradeupgrades the to the newer packages (run the above first!)
#apt-get upgrade <package>is like above, but only upgrades a single package (not that useful unless you have a specific reason)
#apt-get install <package>installs a package
#apt-get remove <package>removes a package
#apt-get autoremoveautomatically removes packages that were installed by dependencies and no longer needed
$apt-cache search <query>searches for the query you gave
$apt-cache show <package>shows info for a package
#yes "" | apt-get install <package>installs a package answering the default answer to everything (you can use yeswith lots of commands)
#apt-get dist-upgradeupgrades everything (and removes some packages) when it might usually be held back.

#apt-get update更新存储库
#apt-get upgrade升级到较新的包(先运行上面的!)
#apt-get upgrade <package>就像上面一样,但只升级单个包(除非你有特定原因,否则没有用)
#apt-get install <package>安装一个包
#apt-get remove <package>删除一个包
#apt-get autoremove自动删除安装的包依赖和不再需要
$apt-cache search <query>搜索您提供的查询
$apt-cache show <package>显示信息包
#yes "" | apt-get install <package>安装一个包回答所有内容的默认答案(您可以使用yes大量命令)
#apt-get dist-upgrade升级所有内容(并删除一些包),当它通常可能被阻止时。

回答by e2-e4

Upgrade to Ubuntu 14.04.1 in order to get PHP 5.5.9 as a package, and benefit from Ubuntu upgrades. I wouldn't go for 5.6.0 in a production environment anyway.

升级到 Ubuntu 14.04.1 以获得 PHP 5.5.9 作为一个包,并从 Ubuntu 升级中受益。无论如何,我不会在生产环境中使用 5.6.0。

From this PHP pageyou get information about the migrations from 5.3 to 5.4 and 5.4 to 5.5.

这个 PHP 页面,您可以获得有关从 5.3 到 5.4 以及从 5.4 到 5.5 的迁移的信息。

Besides the changes and new features mentioned, the PHP teams have worked on memory management and optimization between 5.3 and 5.5.9. These improvements alone motivate the migration.

除了提到的更改和新功能外,PHP 团队还致力于 5.3 和 5.5.9 之间的内存管理和优化。仅这些改进就激发了迁移。

Pieces of advice for the migration

移民建议

  • APC: PHP now embeds OPCache as a replacement of APC. If you used APC variables, some information about OPCacheis available - in my case using the old APC via the new module (name change), php5-apcu(note the 'u'), was the best alternative.

  • The modules were installed in a different directory. If you intend to keep your php.inithe extension_dirmay have to be adjusted

  • In addition, the /etc/php5dir is more demanding in terms of structure: below that dir is mods-available(à la nginx) that contains the list of modules ini files. Then in cli, fpm, apache2... dirs is a conf.ddir that has symbolic links to that main mods-availablemodules ini files ; add only a link if you intend to use that module for that PHP configuration (eg mysqlimay not be necessary for cli).

  • JSON: the module php5-jsonhas to be installed (apt-get install php5-json) in order to get the PHP JSON functions (json_encode, decode...)

  • note that it seems there is a problem linking /etc/php5/MODE/php.ini(MODE being cli, ...) to a mainphp.ini somewhere (eg in fpm) - during Ubuntu updates, an error prevents the installation - I just copied the php.ini since they're the same for all modes in my case.

  • APC:PHP 现在嵌入 OPCache 作为 APC 的替代品。如果您使用 APC 变量,则可以获得有关OPCache 的一些信息- 在我的情况下,通过新模块(名称更改)使用旧 APC php5-apcu(注意“u”)是最好的选择。

  • 模块安装在不同的目录中。如果您打算保留您php.iniextension_dir可能需要调整

  • 此外,该/etc/php5目录在结构方面要求更高:在该目录下方是mods-available(à la nginx),其中包含模块 ini 文件的列表。然后 in cli, fpm, apache2... dirs 是一个conf.d具有指向主要mods-available模块 ini 文件的符号链接的目录;如果您打算将该模块用于该 PHP 配置,则仅添加一个链接(例如,对于mysqli可能不需要cli)。

  • JSON:php5-json必须安装模块( apt-get install php5-json) 才能获得 PHP JSON 函数 ( json_encode, decode...)

  • 需要注意的是,似乎有连接问题/etc/php5/MODE/php.ini(模式下cli,...)到php.ini的地方(例如fpm) -在Ubuntu的更新,出现的错误导致安装-我只是复制在php.ini因为他们是在我的情况下,所有模式都相同。

Besides that the migration went smoothly.

除此之外,迁移进行得很顺利。