PHPBrew: Install and Manage PHP from your $home

php-med-trans-lightFor upcoming Drupal 8 projects I’ve had to update my installed version(s) of PHP. My development system is a System76 Ubuntu LTS laptop. In general I really enjoy the system and try to keep it in a “mainstream or stable state (I only install official packages or packages from PPA — I rarely build from hand). Since I use Ubuntu LTS my OS is currently at 12.04 which uses PHP 5.3.10-1ubuntu3.11 with Suhosin-Patch. This is somewhat dated now.

Since I want to keep a relatively stable system. I looked for a way to install PHP (which can be done by compiling the sourcecode yourself) while not affecting the default PHP managed and installed by Ubuntu’s default package manager APT-GET.

I came across PHPBrew which is a PHP installation and configuration manager from your $home directory. It is similar in vein to Homebrew for OSX, RVM for Ruby or RbEnv for Ruby.

PHPBrew installation managing System + user installed version of PHP on Ubuntu 12.04 LTS.

PHPBrew installation managing System + user installed version of PHP on Ubuntu 12.04 LTS.

As of this writing the installed version of PHPBrew I am using is 1.13.1. From the PHPbrew homepage it can:

- Build php with different variants like PDO, mysql, sqlite, debug …etc.
- Compile apache php module and seperate them by different versions.
- Build and install php(s) in your home directory, so you don’t need root permission.
- Switch versions very easily and is integrated with bash/zsh shell.
- Automatic feature detection.
- Install & enable php extensions into current environment with ease.
- Install multiple php into system-wide environment.

PHPBrew allows you to install different versions of PHP within a hidden home directory folder, typically .phpbrew. Using PHPBrew you may also install Extensions for PHP. I’m currently finding this tool very useful as I work on current Drupal 7 projects — and begin to wet my feet with Drupal 8 development.

Installation and Setup

In order to install PHPBrew you can download the PHAR file and place it in your /usr/bin/ path:

curl -O https://raw.github.com/c9s/phpbrew/master/phpbrew
chmod +x phpbrew
sudo cp phpbrew /usr/bin/phpbrew

Then from your $home directory issue: phpbrew init

Example Usage Commands

From here you can install and use any PHP version you basically want and include Extensions with simple markup. For example on my local development laptop to install php 5.4.2 I issued the following:

# Install php 5.4.2 on Ubuntu 12.04 LTS
$ phpbrew install php-5.4.2 +default +mysql +gettext +mcrypt \
      +intl +iconv +ftp +exif +dba +openssl +soap \
      +apxs2=/usr/bin/apxs2 -- --with-libdir=lib/x86_64-linux-gnu \
      --with-gd=shared --enable-gd-native-ttf \
      --with-jpeg-dir=/usr --with-png-dir=/usr --enable-wddx \
      --with-mysql-sock=/var/run/mysqld/mysqld.sock

In order to fully get GD support using this setup I had to use the following snippet of code for PHPbrew:

phpbrew ext install gd \
-- --with-libdir=lib/i386-linux-gnu \
--with-gd=shared \
--enable-gd-native-ttf \
--with-jpeg-dir=/usr \
--with-png-dir=/usr

With the above 2 commands I have PHP 5.4.2 installed. You can view installed PHP versions using:

phpbrew list

You can switch to another version of PHP using:

phpbrew switch <PHP-VERSION-NAME>

Over time phpbrew may get new features or bugfixes you can easily update phpbrew itself using:

phpbrew self-update

You can install as many version(s) of PHP your project(s) require, new or old with bit-rot, you can safely remove a version of PHP with:

phpbrew remove <PHP-VERSION-NUMBER>

# or phpbrew purge <PHP-VERSION-NUMBER>
# this additionally removes config php files for the installed version.

Lastly, if things go terribly wrong for any reason you can go back to whatever the system is using for its default PHP installation using:

phpbrew off

Since it all lives in your home directory you can safely delete the .phpbrew directory and remove these files from your system and leave you system using the factory default libraries!

Looking for quality Drupal Web Hosting? Look no further than Arvixe Web Hosting!

Tags: , , , , , , , , , , | Posted under Drupal | RSS 2.0

Author Spotlight

David Gurba

David Gurba

I am a web programmer currently employed at UCSB. I have been developing web applications professionally for 8+ years now. For the last 5 years I’ve been actively developing websites primarily in PHP using Drupal. I have experience using LAMP and developing data driven websites for clients in aviation, higher education and e-commerce. If you’d like to contact me I can be reached at david.gurba@arvixe.com

Leave a Reply

Your email address will not be published. Required fields are marked *


6 × = 18

You may use these HTML tags and attributes: <a href="" title="" rel=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>