PHPbrew and VirtPHP - Two incredibly effective tools for PHP developers

By jason, 9 December, 2014
VirtPHP

The evolution of PHP from a mere server-side scripting language to a full-fledged general-purpose programming language hasn't gone unnoticed in the recent years. To top that, the innovative versions of PHP that are being launched into the web market on a regular basis have added fuel to the ever-rising popularity of the web development software. If you're a PHP developer, you might have come across a situation where you need to switch from one PHP version to another. Well, just like Ruby and Python, now even PHP has effective tools for dealing with the concept of switching between multiple versions of PHP. Today, through this blog, I'll be highlighting the features of two such awesome PHP tools that have helped in managing and installing multiple PHP versions conveniently. These tools are: PHPBrew and VirtPHP. So, let's take a closer look at the features of these amazing PHP tools.

Firstly, let's get to know PHPbrew better

Released in the year 2012, PHPbrew is a fabulous PHP tool that allows PHP developers across all skill-levels to build and install multiple PHP versions by placing the same into a folder that's located within your home directory. In simple words, PHPbrew will simply build multiple versions for the PHP Installed in your system, followed by placing them in the home folder and further allowing you to switch between these versions as and when required.

A brief on installing PHPbrew in your system

You require the following utils for installing PHPbrew into your computer system:

  • autoconf
  • automake
  • curl
  • pcre
  • re2c
  • mhash
  • libtool
  • icu4c
  • gettext
  • jpeg
  • libxml2
  • mcrypt
  • gmp
  • libevent

If you're using a Mac, then after acquiring all the above mentioned utils, simply run the following command:

$ brew install automake autoconf curl pcre re2c mhash libtool
icu4c gettext jpeg libxml2 mcrypt gmp libevent
$ brew link icu4c

Now, in order to install PHPbrew, you just need to execute the following commands:

$ curl -L -O

https://github.com/phpbrew/phpbrew/raw/master/phpbrew

$ chmod +x phpbrew
$ sudo mv phpbrew /usr/bin/phpbrew

Here is the command that you would need to execute for initializing your system:

$ phpbrew init

Some easy-to-execute PHPbrew commands

Here are some of the finest PHPbrew commands that allow you to perform varied tasks:

1. Command for listing PHP versions that are available for installation

$ phpbrew known

5.6: 5.6.1, 5.6.0 ...
5.5: 5.5.17, 5.5.16, 5.5.15, 5.5.14, 5.5.13, 5.5.12, 5.5.11, 5.5.10 ...
5.4: 5.4.33, 5.4.32, 5.4.31, 5.4.30, 5.4.29, 5.4.28, 5.4.27, 5.4.26 ...
5.3: 5.3.29, 5.3.28, 5.3.27, 5.3.26, 5.3.25, 5.3.24, 5.3.23, 5.3.22 ...

2. Command for installing a specific version of PHP

$ phpbrew install 5.5.15

3. Command for changing php version

$ phpbrew switch php-5.5.17

Now, let's have a look at what VirtPHP has in store for you:

VirtPHP is a tool that's used for creating and managing multiple isolated PHP interfaces on a single machine. Thus, you can choose to run multiple PHP development projects that are using different versions of the PEAR packages and PECL extensions. With VirtPHP, you can even avail the flexibility of specifying an innovative version of PHP in case multiple PHP versions have already been installed in your system.

A word about installing VirtPHP

In order to install VirtPHP In your system, all you need to do is simply go to the virtPHP release page here and search for the latest release by VirtPHP. Once you're able to find it, just right click on the “virtphp.phar” link associated with the same.

Creating PHP environments using VirtPHP

The best part of using VirtPHP is that it allows you to create multiple PHP environments by fetching the version of PHP that is already installed in your system. Here is the command that needs to be executed for creating PHP environment using VirtPHP:

virtphp create airpair-api

Well before creating an environment, it is necessary for you to be certain about using the right PHP Version. For this, you simply need to run the following command:

$ which php
/Users/phil/.phpbrew/php/php-5.6.0/bin/php

Installing PECL extensions using VirtPHP

By installing PECL extensions, you can not only check the proper functioning of an app but can even try a variety of PHP versions for meeting different web development requirements. Here are the commands that need to be executed for the same:

(airpair-api) $ pecl install xdebug
(airpair-api) $ pecl install memcached-1.0.2

Conclusion

Although playing with multiple versions of PHP can seem to be a little confusing in the beginning, but with the right set of tools in hand, you can get on with the activity in a hassle-free manner. Here's hoping the descriptions of PHPBrew and VirtPHP would have helped you grow your knowledge base regarding tweaking of PHP versions.