同一个盒子上有多个 PHP 版本

发布于 2024-08-15 01:39:28 字数 258 浏览 5 评论 0原文

是否可以在同一个机器上运行多个版本的 PHP(例如 Rails)。这是我的问题,我需要开始开发一个新项目,并计划使用 PHP 5.3,以便我可以使用最新的 Zend 框架和活动记录。
但是,我需要托管应用程序的机器有 PHP 4.4,并且那里还托管着其他几个应用程序。我不想升级服务器上的 PHP 版本,因为过去我在升级 PHP 版本和弃用的功能时遇到了很多问题。
我想知道是否可以在同一个盒子上安装多个版本的 PHP,然后以某种方式指定您希望应用程序加载的版本(类似于 Rails)

Is it possible to have multiple versions of PHP running on the same box ( like rails ) . Here is my problem , I need to start development on a new project and was planning to use PHP 5.3 for it so that I can use the latest Zend framework and active record with it .
However the machine where I need to host my application has PHP 4.4 and there are several other applications hosted there . I do not want to upgrade the PHP version on the server as in the past I have faced a lot of issues while upgrading the PHP version and deprecated functions .
I was wondering if it is possible to have multiple version of PHP on the same box and then somehow specify the version that you want your application to load ( similar to rails )

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

朦胧时间 2024-08-22 01:39:28

是的,这是可能的。事实上,很多服务器都是这样运行的。您可能会不时看到 .php4 和 .php5 扩展名,指示应使用哪个版本来处理特定脚本。

ServerFault 解决了这个问题

同时运行 php4 和 php5

Yes, it is possible. In fact, many servers operate this way. You may see .php4 and .php5 extensions from time to time indicating which version that particular script should be handled with.

ServerFault addressed this question

Running php4 and php5 along side each other

Hello爱情风 2024-08-22 01:39:28

您可以使用 Docker 在同一个机器上运行多个 PHP 版本。

示例命令如下:

sudo docker run -d -p 8055:80 -v /var/www:/var/www \
  -v /etc/apache2/sites-available:/etc/apache2/sites-available \
  -v /etc/apache2/sites-enabled:/etc/apache2/sites-enabled \
  codeyourdream/apache-sendmail-php55

此命令的作用如下:

  • 它转发您的本地 /var/www/etc/apache2/sites-available/etc/ apache2/sites-enabled 复制到 Docker 容器对应的文件夹中。如果您的本地网站和/或 apache 配置位于不同的文件夹中,请替换 -v 值的第一部分。
    即格式为:
    <代码>
    docker run -v /host/directory:/container/directory -other -options image_name command_to_run
  • 它将本地计算机的端口 8055 转发到 Docker 容器的端口 80
  • 它从“codeyourdream/apache-sendmail-php55”图像运行容器

如果运行此命令,则所有本地网站都应该可以通过端口 8055 访问 即通过 http://localsite:8055 等 URL 并由 PHP 5.5 处理,

请参阅 https://codeyourdream.com/blog/how-run-multiple-php-versions-apache-one-linux-machine-using-docker 了解更多详细信息。
附属说明:这是我团队的博客。

You can run multiple PHP versions on the same box using Docker.

An example command would be:

sudo docker run -d -p 8055:80 -v /var/www:/var/www \
  -v /etc/apache2/sites-available:/etc/apache2/sites-available \
  -v /etc/apache2/sites-enabled:/etc/apache2/sites-enabled \
  codeyourdream/apache-sendmail-php55

Here's what this command does:

  • It forwards your local /var/www, /etc/apache2/sites-available and /etc/apache2/sites-enabled to the corresponding folders of Docker container. If your local websites and/or apache configs are located in different folders, replace the first part of -v value.
    I.e. the format is:

    docker run -v /host/directory:/container/directory -other -options image_name command_to_run
  • It forwards port 8055 of your local machine to port 80 of Docker container
  • It runs the container from "codeyourdream/apache-sendmail-php55" image

If you run this command, all your local websites should be available via port 8055 (i.e. via URLs like http://localsite:8055) and processed by PHP 5.5

See https://codeyourdream.com/blog/how-run-multiple-php-versions-apache-one-linux-machine-using-docker for more details.
Affiliation note: this is my team's blog.

遗心遗梦遗幸福 2024-08-22 01:39:28

一种可能性是使用 PHP 的一个版本作为 Apache 模块,而另一个版本作为 CGI ;但我更喜欢的一个想法是拥有:

  • 几个不同的 Apache 实例,
  • 每个实例监听不同的端口(例如,端口 44000 上的 PHP 4.4 和端口 53100 上的 PHP 5.3.1)
  • 并且每个都使用不同版本的 PHP

这样,您就拥有完全不同的环境,彼此独立工作,并且您可以在每个环境中配置/修改您想要的任何内容,而不必冒破坏任何其他环境的风险。

(如果您不想在 URL 中包含端口号,我想您可以在不同的 Apache 实例前面放置一个代理,这样看起来就只有一个)

A possiblity is using one version of PHP as an Apache module, and the other version as a CGI ; but an idea I kind of like better is to have :

  • Several distinct instances of Apache,
  • Each one listening on a different port (for instance, PHP 4.4 on port 44000, and PHP 5.3.1 on port 53100)
  • And each one using a different version of PHP

This way, you have totally different environments, that works independantly of each other, and you can configure/modify anything you want in each environment without risking breaking any of the others.

(And if you don't want to have port numbers in your URLs, I suppose you can put a proxy in front of your distinct Apache instances, so it seems there is only one)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文