简体   繁体   中英

Does php have an equivalent to python's virtualenv or ruby's sandbox?

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.

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

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

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.

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

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.

(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:

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

and in your php files:

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.

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM