php 是否有相当于 python 的 virtualenv 或 ruby 的沙箱?
我习惯使用 python 的 virtualenv 工具创建单独的环境,可以模拟我编写的项目的部署环境。
现在,我将从事一个 php 项目,我想知道是否有与之等效的项目?具体来说,我希望能够使用一种(较旧的)版本的 php 在 apache 上运行一个虚拟主机,而其他所有内容都在正常的最新版本上运行。
我的开发机器运行的是 ubuntu 11.04,因此在该平台上工作的解决方案将是首选。
I'm used to using python's virtualenv tool to create separate environments that can mimic deployment environments for projects I write.
Now, I'm going to be working on a php project and I'm wondering if there's any equivalent to that? Specifically I'm hoping to be able to run one virtualhost on apache with one (older) version of php, while everything else runs on the normal up to date version.
My development machine is running ubuntu 11.04, so solutions that work on that platform would be preferred.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(8)
假设您使用 mod_php,则无法将多个不同版本加载到同一个 Apache 实例中。如果您将 PHP 作为 CGI 或 FastCGI 运行,则可以运行多个不同的版本,但这本身会引入与 mod_php 行为上的一些差异。
Assuming that you are using mod_php, there is no way to load multiple different versions into the same Apache instance. You can run multiple different versions if you're running PHP as CGI or FastCGI, but this will itself introduce some differences in behavior from mod_php.
虚拟机的另一个替代方案是 docker。
Another alternative to virtual machines is docker.
由于使用 mod_php 在 apache 中加载不同版本的 php 似乎是不可能的,模仿部署和开发设置的最简单方法是使用虚拟机,您表示希望避免这种情况。
减轻开发人员的虚拟机负担的一种方法是使用 vagrant 之类的东西。使用两个文件(vagrant 文件和 Chef/puppet 文件),您可以对虚拟机进行“版本控制”,轻松创建它们并在需要时为每个项目销毁它们。
As loading different versions of php within apache with mod_php seems not to be posible, the easiest way of mimicking deployment and development setups will be with a virtualmachine, which you stated you would like to avoid.
One way of making the burden of vm's for developers a bit easier is to use something like vagrant. With two files (the vagrant file, and the chef/puppet file) you can "version" your vm's, easily create them and destroy them for each project and when needed.
virtPHP 是一个用于在一台机器上创建和管理多个隔离的 PHP 环境的工具。它就像 Python 的 virtualenv,但适用于 PHP。 (自述文件)
https://github.com/virtphp/virtphp
virtPHP is a tool for creating and managing multiple isolated PHP environments on a single machine. It's like Python's virtualenv, but for PHP. (README)
https://github.com/virtphp/virtphp
您可能对此感兴趣:https://github.com/phpenv/phpenv
You might be interested in this: https://github.com/phpenv/phpenv
(多年没有编写 php 代码,所以这可能已经过时了)
据我记得,您只需指向库所在的另一个目录(包括 PATH),使用类似以下内容:
在您的 php 文件中:
PHP 从来没有真正PEAR 拥有像 perl/python/ruby 这样强大的打包系统和库存储库,PEAR 正在尝试朝这个方向发展,但相比之下它非常封闭,并且很难在多项目环境中进行配置。
Phark 正在尝试为 php 构建一个 brew/bundler 端口,https://github.com/lox/phark,尽管它还没有准备好部署。
(Haven't coded php in years, so this might be outdated)
As far as I remember you just had to point to another directory where your libraries reside (include PATH), using something like:
and in your php files:
PHP never really had a robust packaging system and library repository like perl/python/ruby has, PEAR was trying to move in that direction but it is very closed in comparison and was hard to configure in multiproject environments.
Phark is trying to build a brew/bundler port for php, https://github.com/lox/phark, although it's not deployment ready.
到目前为止,这个问题还没有现成的解决方案。唯一接近的解决方案是 Vagrant 和 puPHPet.com,如下所述: https://drupal.org/node/2055947
为什么我们不能有像python的virtualenv或者ruby的rbenv这样的环境呢?它构成了一个很好的开源项目。如果我们想在沙箱中而不是全局测试某些库,PHP 的多个实例会很方便。我们可以使用像 Composer 这样的包管理器来安装不同项目的依赖项。
As of now, there is no out of the box solution to this problem. The only solution which comes close is Vagrant and puPHPet.com as discussed here: https://drupal.org/node/2055947
Why can't we have an environment like python's virtualenv or ruby's rbenv? It makes up a nice open source project. Multiple instances of PHP can be handy if we want to test out some libraries in sandboxes rather than globally. We can install dependencies for different projects using a package manager like Composer.
带有 PHP 选择器的 Cloudlinux 已经有这个功能很久了。它与流行的控制面板(如 CPanel、DirectAdmin 等)集成。
每个 Linux 帐户都可以有自己的 php 版本,并选择适合的任何扩展。
https://www.cloudlinux.com/php-selector
Cloudlinux with PHP Selector has this for ages. It is integrated with popular control panels like CPanel, DirectAdmin etc.
Each linux account can have its own version of php and select any extensions they sit fit.
https://www.cloudlinux.com/php-selector