Managing Multiple PHP Version Using PHPBrew

If you are a PHP developer I’m sure you have been in a situations where you need to install multiple versions of PHP. This can happen when you have a deployable application which must be compatible with different PHP versions.

There will also be times, like now, where a new version of PHP is out that you need to test on your application. It might be you’re trying to figure out if its faster so you can convince your lead-dev to let you mess with the prod server (fear) or you’re just nosey as to what all the fuss is about. Fortunately there is a better way!

Introducing PHPBrew

phpbrew builds and installs multiple version php(s) in your $HOME directory,  it helps you manage and switch between different PHP versions with ease. It provides a command line interface where you can install different versions with a single command, set a default, switch between them and much more.



Install build dependencies:

$ sudo apt install php7.0-cli php7.0-curl libxml2-dev libssl-dev libbz2-dev libmcrypt-dev libreadline-dev libxslt1-dev autoconf libcurl4-openssl-dev make libpq-dev

Download, Install and Initialize.

To install you just need to execute the following commands

$ curl -L -O
$ chmod +x phpbrew
$ sudo mv phpbrew /usr/bin/phpbrew

Now you must initialize your system executing the following command.

$ phpbrew init

Then add these lines to your .bashrc, .bash_profile or .zshrc file

[[ -e ~/.phpbrew/bashrc ]] && source ~/.phpbrew/bashrc

Using PHPBrew

If installed correctly, the phpbrew command is available anywhere in your terminal. Let’s see how to use it to manage PHP versions.

Phpbrew commands

List PHP versions available to be installed

$ phpbrew known
7.1: 7.1.0 ...
7.0: 7.0.14, 7.0.13, 7.0.12, 7.0.11, 7.0.10, 7.0.9, 7.0.8, 7.0.7 ...
5.6: 5.6.29, 5.6.28, 5.6.27, 5.6.26, 5.6.25, 5.6.24, 5.6.23, 5.6.22 ...
5.5: 5.5.38, 5.5.37, 5.5.36, 5.5.35, 5.5.34, 5.5.33, 5.5.32, 5.5.31 ...
5.4: 5.4.45, 5.4.44, 5.4.43, 5.4.42, 5.4.41, 5.4.40, 5.4.39, 5.4.38 ...

Install a PHP specific version of PHP

$ phpbrew install 7.0

Install a PHP with specific libraries or virtual variant.

$ phpbrew install 7.0 +default +fpm +pgsql +pdo

List php version versions available in your system

$ phpbrew list
Installed versions:
* php-7.0.11

Change php Version

$ phpbrew switch php-7.0.11

Disable Phpbrew

$ phpbrew off
phpbrew is turned off.

After disable Phpbrew you can execute the following command to check the current status of system

$ phpbrew list
Installed versions:
* (system)

As you can see the PHP version available if the normal PHP version your system have, off course you enable again other version using the switch command explained above.

1 Comment

  1. A WordPress Commenter

    November 20, 2018 at 8:39 am

    Hi, this is a comment.
    To get started with moderating, editing, and deleting comments, please visit the Comments screen in the dashboard.
    Commenter avatars come from Gravatar.

Leave a Reply