Normally while we are in the development phase, we normally deal with a single version of PHP which is bundled with WAMP, MAMP or XAMPP. But how about if you want to switch your PHP [PHP Templates]version just to test your application on the different version of PHP? Also, what if you want to run your different application on the different version of PHP on the same machine? Just like Ruby and Python we now have the same tool available for PHP as well.
In this article, we will be talking about two different tools which provide the facility to run a multiplr version of PHP on a single machine and you can easily switch those versions from one to another. These tools are PHPBrew and VirtPHP. We will see how to get started with these best php tools.
100,000+ Designs, Documents Templates in PDF, Word, Excel, PSD, Google Docs, PowerPoint, InDesign, Apple Pages, Google Sheets, Publisher, Apple Numbers, Illustrator, Keynote. - START DOWNLOADING
– Build PHP with different variants like PDO, MySQL, SQLite, debug
– Build and install PHP(s) in your home directory, so you don’t need root permission.
– Switch versions very easily.
– Install & enable PHP extensions into current environment with ease
– Install multiple PHP into system-wide environment
Before we start an installation, I would suggest looking at requirement first. Because we will need some development packages to be installed to run the PHPBrew.
Installing PHPBrew is just a matter of 3 commands and you are done with that.
curl -L -O https://github.com/phpbrew/phpbrew/raw/master/phpbrew
chmod +x phpbrew
sudo mv phpbrew /usr/bin/phpbrew
The basic command to start PHPBrew is phpbrew init. We can get more details on usage at Github(https://github.com/phpbrew/phpbrew/#basic-usage). After this you will need to add below line to .bashrc or .zshrc file:
Now we will see various commands which we need to know to deal with PHPBrew effectively.
List known PHP Versions: phpbrew known
List known old Versions: phpbrew known –old
Build and Install
We can get a list of known version as mentioned above, now pick any version and we will install the same using below command.
phpbrew install 5.4.0 +default
Above command will install PHP 5.4.0 in home directory with all default variant set because we have added +default in command. If you want to setup specific variants only then you can specify those in you install command. Let’s assume we want PHP which needs only PDO and SQLite variants than we can use command.
phpbrew install 5.4.0 +pdo +sqlite
Switching can be done using two ways, using use and switch command. Let’s see the difference between both commands.
phpbrew use php-5.4.0
phpbrew switch php-5.4.0
use can be used if you want to use specific version while you are in the console and it will be available for that session only. The “switch” will switch the default version of PHP. Let’s see how it works:
$ phpbrew switch php-5.4.0
$ php -v
Copyright (c) 1997-2014 The PHP Group
Zend Engine v2.6.0, Copyright (c) 1998-2014 Zend Technologies
We have seen that how we can use the specific version of PHP using PHPBrew. But if you want to turn of PHPBrew PHP version and use the system PHP version you can fire below command to achieve the same.
Unlike PHPBrew, VirtPHP lets you create an isolated environment for your specific application. Interesting, isn’t it? It’s like Python’s virtualenv but for PHP.
Imagine you have one application which needs some specific extension but you don’t want that to be available to other applications then we can separate environment for that application and install required extension for that environment only.
Just like PHPBrew, it’s just a matter of 3 commands and you are done.
$ wget https://github.com/virtphp/virtphp/releases/download/v0.5.2-alpha/virtphp.phar
chmod +x virtphp.phar
sudo mv virtphp.phar /usr/bin/virtphp
You can confirm successful installation using virtphp -V command.
For creating an environment, first let’s change the PHP version we want to use.
phpbrew use 5.4.0
Now we have changed the version of PHP which want to use. It’s time to create an environment.
virtphp create demo-app
Once an environment is created, you will get success message for the same along with the command to activate newly create environment. We may have use below command to activate the same.
After this, you will find “demo-app” before the $ sign, which indicates that you are inside that particular environment. Whatever we do now will be limited to that environment only. Let’s install xdebug in that.
(demo-app) $ pecl install xdebug
Once you are done with your environment then just run the “deactivate” command and you will be out of that environment.
In the beginning, you may find this process kind of confusing but when you get some experience with this, you will find the benefits of having various version of PHP on a single system and using the same. [Free PHP Templates]
Hope you find this process easy to use and follow. You can share your feedback in comments below.