php有相当于python的virtualenv或ruby的沙箱吗?

时间:2021-05-02 23:27:52

I'm used to using python's virtualenv tool to create separate environments that can mimic deployment environments for projects I write.

我习惯使用python的virtualenv工具来创建可以模仿我编写的项目的部署环境的独立环境。

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.

现在,我将要开发一个php项目,我想知道是否有相同的东西?具体来说,我希望能够在一个(较旧的)版本的php上运行apache上的一个虚拟主机,而其他一切都在正常的最新版本上运行。

My development machine is running ubuntu 11.04, so solutions that work on that platform would be preferred.

我的开发机器正在运行ubuntu 11.04,因此首选在该平台上运行的解决方案。

7 个解决方案

#1


10  

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.

假设您使用的是mod_php,则无法将多个不同版本加载到同一个Apache实例中。如果您将PHP作为CGI或FastCGI运行,则可以运行多个不同的版本,但这本身会在mod_php中引入一些行为差异。

#2


7  

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.

由于使用mod_php在apache中加载不同版本的php似乎不具备可能性,因此模拟部署和开发设置的最简单方法是使用虚拟机,您声明要避免使用虚拟机。

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.

为开发人员增加vm负担的一种方法是使用像vagrant这样的东西。使用两个文件(vagrant文​​件和chef / puppet文件),您可以“版本化”您的虚拟机,轻松创建它们并在需要时为每个项目销毁它们。

#3


7  

Another alternative to virtual machines is docker.

虚拟机的另一种替代方案是docker。

#4


5  

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)

virtPHP是一种在单台机器上创建和管理多个独立PHP环境的工具。它就像Python的virtualenv,但对于PHP。 (自述)

https://github.com/virtphp/virtphp

https://github.com/virtphp/virtphp

#5


2  

(Haven't coded php in years, so this might be outdated)

(多年没有编写php,所以这可能已经过时了)

As far as I remember you just had to point to another directory where your libraries reside (include PATH), using something like:

据我所知,你只需要指向你的库所在的另一个目录(包括PATH),使用类似的东西:

include_path = .:/usr/local/lib/php:./include (this goes in php.ini, default libararies)

and in your php files:

在你的PHP文件中:

ini_set("include_path", ".:../:./include:../include");

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.

PHP从来没有真正拥有像perl / python / ruby​​这样的强大的打包系统和库存储库,PEAR正试图朝这个方向发展,但它相比非常封闭,并且在多项目环境中很难配置。

Phark is trying to build a brew/bundler port for php, https://github.com/lox/phark, although it's not deployment ready.

Phark正试图为php建立一个brew / bundler端口,https://github.com/lox/phark,尽管它还没有部署就绪。

#6


2  

You might be interested in this: https://github.com/phpenv/phpenv

您可能对此感兴趣:https://github.com/phpenv/phpenv

#7


1  

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.

截至目前,没有开箱即用的解决方案来解决这个问题。接近的唯一解决方案是Vagrant和puPHPet.com,如下所述:https://drupal.org/node/2055947为什么我们不能拥有像python的virtualenv或ruby的rbenv这样的环境?它构成了一个很好的开源项目。如果我们想要在沙箱而不是全局中测试一些库,那么PHP的多个实例可以很方便。我们可以使用像Composer这样的包管理器为不同的项目安装依赖项。

#1


10  

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.

假设您使用的是mod_php,则无法将多个不同版本加载到同一个Apache实例中。如果您将PHP作为CGI或FastCGI运行,则可以运行多个不同的版本,但这本身会在mod_php中引入一些行为差异。

#2


7  

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.

由于使用mod_php在apache中加载不同版本的php似乎不具备可能性,因此模拟部署和开发设置的最简单方法是使用虚拟机,您声明要避免使用虚拟机。

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.

为开发人员增加vm负担的一种方法是使用像vagrant这样的东西。使用两个文件(vagrant文​​件和chef / puppet文件),您可以“版本化”您的虚拟机,轻松创建它们并在需要时为每个项目销毁它们。

#3


7  

Another alternative to virtual machines is docker.

虚拟机的另一种替代方案是docker。

#4


5  

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)

virtPHP是一种在单台机器上创建和管理多个独立PHP环境的工具。它就像Python的virtualenv,但对于PHP。 (自述)

https://github.com/virtphp/virtphp

https://github.com/virtphp/virtphp

#5


2  

(Haven't coded php in years, so this might be outdated)

(多年没有编写php,所以这可能已经过时了)

As far as I remember you just had to point to another directory where your libraries reside (include PATH), using something like:

据我所知,你只需要指向你的库所在的另一个目录(包括PATH),使用类似的东西:

include_path = .:/usr/local/lib/php:./include (this goes in php.ini, default libararies)

and in your php files:

在你的PHP文件中:

ini_set("include_path", ".:../:./include:../include");

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.

PHP从来没有真正拥有像perl / python / ruby​​这样的强大的打包系统和库存储库,PEAR正试图朝这个方向发展,但它相比非常封闭,并且在多项目环境中很难配置。

Phark is trying to build a brew/bundler port for php, https://github.com/lox/phark, although it's not deployment ready.

Phark正试图为php建立一个brew / bundler端口,https://github.com/lox/phark,尽管它还没有部署就绪。

#6


2  

You might be interested in this: https://github.com/phpenv/phpenv

您可能对此感兴趣:https://github.com/phpenv/phpenv

#7


1  

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.

截至目前,没有开箱即用的解决方案来解决这个问题。接近的唯一解决方案是Vagrant和puPHPet.com,如下所述:https://drupal.org/node/2055947为什么我们不能拥有像python的virtualenv或ruby的rbenv这样的环境?它构成了一个很好的开源项目。如果我们想要在沙箱而不是全局中测试一些库,那么PHP的多个实例可以很方便。我们可以使用像Composer这样的包管理器为不同的项目安装依赖项。