Download the PHP package virtphp/virtphp without Composer
On this page you can find all versions of the php package virtphp/virtphp. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download virtphp/virtphp
More information about virtphp/virtphp
Files in virtphp/virtphp
Package virtphp
Short Description virtPHP is a tool to create isolated PHP environments.
License MIT
Homepage http://virtphp.org
Informations about the package 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.
virtPHP creates isolated environments so that you may run any number of PHP development projects, all using different versions of PEAR packages and different PECL extensions. You may even specify a different version of PHP, if your system has various installations of PHP.
To install multiple versions of PHP, we suggest taking a look at the phpenv and php-build projects or phpbrew and using virtPHP with them, to manage multiple virtual PHP environments.
*Note: virtPHP is currently only targeted to command line php
(php-cli) for nix based systems.**
Installation
Download the virtphp.phar
file from the latest release and place it in /usr/local/bin
or wherever it's accessible from your PATH
.
Optionally, you may clone this repository and build the phar file yourself.
Usage
virtPHP is a command-line tool. To get started, you'll probably want to check out what it can do. To do this, just execute it without any arguments, like this:
If you have the phar file set executable (i.e. chmod 755
), then you can execute it like this:
Or, if it's in your PATH
, like this:
We recommend putting it in your PATH
and aliasing it to virtphp
, so that you can run it like this:
For convenience, the following examples will assume you have simply downloaded virtphp.phar
and have not placed it in your PATH
or set it executable.
Getting Started
To create a new virtPHP environment, use the create
command:
By default, this will create a new PHP environment in myenv/
, using your system PHP as the base.
After creating the environment, you may activate it so that you now use the new environment in your shell:
After activating your environment, you'll notice that your shell changes to include the name of your virtPHP environment, like this:
And, when you run which php
, your shell session reports it is now using PHP from your virtPHP environment:
Now, let's install a PECL extension and a PEAR package.
(I'm not showing any of the console output here, in case you were wondering.)
What's cool here is that you didn't have to use sudo
to install these commands, and if you run pear list -a
, you'll see both PHPUnit and pecl/mongo listed as being installed. Now, any project running in the current, activated virtPHP environment can make use of these packages.
To return your environment back to normal settings and discontinue using your virtPHP environment, simply use the deactivate
command. It doesn't matter where you are when you run it—it's available to your entire virtPHP environment.
Now, depending on your base environment, when you run pear list -a
, you won't see the PHPUnit or pecl/mongo packages that you just installed.
To start up your virtPHP environment again, just source the activate
script for the virtPHP environment you want to use.
Altogether, that's pretty neat, huh?
So you've setup one or two or even eleven different environments. Keeping track of all of them in your head can lead to cluster headaches, right? So to list out all the environments you have installed, use the show command.
This will give you a nice list of all the environments you've created and the path to each.
Because virtPHP creates physical folders and files for all of it's work, make sure you use the built in commands for destroying or cloning environments, otherwise things can get messy. However, if an environment does get out of sync you can perform a resync of a particular environment.
If you do another show, you will see the updated path in the list of your enviornments.
Under the Covers
When you create a new virtPHP environment, it creates a new directory and sets up a virtual environment for PHP within it. For example, the myenv/
environment directory looks something like this:
When you activate the environment, the bin/
directory becomes a part of your PATH
. When you install a PECL extension, the extension is placed in lib/php/
(as you can see in this example, with mongo.so
), and when you install a PEAR package, it is placed in share/php/
(and console commands are placed in bin/
, as you can see in this example with phpunit
).
To be helpful, we have already installed Composer for you. When you activate a virtPHP environment, then you have access to the composer
command.
Advanced Concepts
Let's say you need to use the same host machine to develop multiple projects, all requiring different versions of PHP and different versions of PECL extensions or PEAR packages. virtPHP was made for this!
Specifying a PHP Build for virtPHP
If you have multiple builds of PHP on your system, you can tell virtPHP which one to use, when creating a new environment.
In this case, we have project1-env
and project2-env
, both of which use PHP 5.4.25. One of the projects, however uses the older pecl/mongo version 1.2 series, while the other project uses the pecl/mongo 1.4 series. virtPHP makes the use of both extensions possible on the same system. Here's how:
Now, we are able to use version 1.2.12 of pecl/mongo, when working on project1-env, and we can use version 1.4.5 of pecl/mongo, when working on project2-env. We just need to activate the environment we are working on first.
In the same way, working with different versions of PHP for other projects is simple. For example, in project3-env
, we are using PHP 5.5.
Using phpbrew to install multiple PHP versions
In the previous examples, we told virtPHP to use a specific build of PHP when creating new environments. To use virtPHP in this way, you'll need to install different builds of PHP. You can download the source, configure it, and build it on your own, or you may use phpbrew to do this for you.
First, install phpbrew on your system, like this (follow any instructions these commands print to the screen):
Then, you should init a bash script for your shell environment, which will place a bashrc
file in the ~/.phpbrew
folder.
Then source this file to your .bashrc
or .zshrc
file with this line:
Now, we can view and install a few versions of PHP, and control the variants that can be installed with it, with the following commands.
This may take a while, so grab a few cups of coffee. phpbrew command shown with the default
, debug
, and mysql
variants included.
Variants can be installed individually, or in 'virtual variants'
After installing the spcified version of phpbrew
, we can activate a specific version like this:
...switch between different versions:
...or, return to the system version:
So, why would we need virtPHP, if we can do this? virtPHP goes beyond phpbrew.
With virtPHP, you may install different PECL extensions, different PEAR packages, and manage separate php.ini
configs for the same version and build of PHP. This way, projects you are developing that share the same PHP version but different configuration may be developed on the same system using different virtual PHP environments. virtPHP can work together with phpbrew to achieve this.
Known Issues
- .pearrc not found issue
If you get an error stating the script couldn't access the
.pearrc
file (or can't find it), you can either try changing the permissions on your[USER_DIR]/.pearrc
file or remove it entirely. This issue seems to occur sporadically.
Contributing
If you would like to help, take a look at the list of issues. Fork the project, create a feature branch, and send us a pull request.
To ensure a consistent code base, you should make sure the code follows the coding standards, which we borrowed from Symfony.
Running the Tests
You may use the provided Vagrantfile to start up a VM and run tests in a clean environment. You will need VirtualBox and Vagrant installed on your system.
Building the Phar File
virtPHP is distributed as an executable phar file. The bin/compile
script handles building this file. To build the phar file, change to the location of your virtPHP project clone and execute the compile
script like this:
This should build a file named virtphp.phar
in your current directory. You may move this file to wherever you like and use it for creating virtPHP environments.
Requirements
PHP 5.3.3 or above.
License
Copyright (c) 2013-2014 Jordan Kasper, Ben Ramsey, Jacques Woodcock
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
All versions of virtphp with dependencies
symfony/console Version >=2.3,<2.5
symfony/filesystem Version ~2.3
symfony/finder Version ~2.3
symfony/process Version ~2.3