Skip to content
This repository

Brew & manage PHP versions in pure PHP at HOME

Octocat-spinner-32 bin Moved files to sh directory January 22, 2014
Octocat-spinner-32 completion updated completion for `phpbrew ext` subcommands, so only pertinent e… December 29, 2013
Octocat-spinner-32 doc Add test paln September 17, 2012
Octocat-spinner-32 screenshots Add screenshots February 08, 2012
Octocat-spinner-32 scripts fix conflict February 23, 2014
Octocat-spinner-32 sh Moved files to sh directory January 22, 2014
Octocat-spinner-32 src restore ExtensionInstallerTest.php, modify ExtensionInstaller.php March 25, 2014
Octocat-spinner-32 tests restore ExtensionInstallerTest.php, modify ExtensionInstaller.php March 25, 2014
Octocat-spinner-32 .gitignore fix ExtensionInstallerTest bug, path_ok need full path March 25, 2014
Octocat-spinner-32 .pharcc.yml Removed the dependency on symfony/process as it is not used December 03, 2013
Octocat-spinner-32 .travis.yml Add HHVM December 15, 2013
Octocat-spinner-32 Merge branch 'master' into develop December 11, 2013
Octocat-spinner-32 update contributor list December 03, 2013
Octocat-spinner-32 Doxyfile Update Doxyfile for QUIET mode July 12, 2012
Octocat-spinner-32 Add CONTRIBUTORS and March 11, 2013
Octocat-spinner-32 LICENSE MIT License March 09, 2013
Octocat-spinner-32 Update January 02, 2014
Octocat-spinner-32 more description for requirement. December 11, 2013
Octocat-spinner-32 build.xml Use bin/phpbrew to test cli commands for Jenkins July 11, 2012
Octocat-spinner-32 composer.json Checking in changes prior to tagging of version 1.13.1. February 18, 2014
Octocat-spinner-32 package.ini Bump version to 1.8.18 March 20, 2013
Octocat-spinner-32 package.xml Releasing 1.8.18 March 21, 2013
Octocat-spinner-32 phpbrew Merge branch 'master' of March 25, 2014
Octocat-spinner-32 Moved "ext disable" to - refs #179 January 23, 2014
Octocat-spinner-32 phpdox.xml Add build.xml for Jenkins CI July 11, 2012
Octocat-spinner-32 phprelease.ini Checking in changes prior to tagging of version 1.13.0. February 03, 2014
Octocat-spinner-32 phpunit-ci.xml Add filter to phpunit-ci config July 11, 2012
Octocat-spinner-32 phpunit.xml Enable colors July 11, 2012
Octocat-spinner-32 update todo December 04, 2013


phpbrew builds and installs multiple version php(s) in your $HOME directory.

phpbrew also manage the environment variables, so you can use, switch php version whenever you need.

What phpbrew can do for you:

  • 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.


Please see Requirement before you get started. you need to install some development packages for building PHP.

Install phpbrew

Just download it:

curl -O
chmod +x phpbrew
sudo cp phpbrew /usr/bin/phpbrew

Basic usage

Init a bash script for your shell environment:

$ phpbrew init

Then add these lines to your .bashrc or .zshrc file:

$ source ~/.phpbrew/bashrc

You may setup your prefered default prefix for looking up libraries, available options are macports, homebrew, debian, ubuntu or a custom path:

For Homebrew users:

$ phpbrew lookup-prefix homebrew

For Macports users:

$ phpbrew lookup-prefix macports

To list known versions:

$ phpbrew known
Available stable versions:

To list known subversion versions:

$ phpbrew known --svn

To list known older versions (less than 5.3):

$ phpbrew known --old

Build And Install

Simply build and install PHP with default variant:

$ phpbrew install 5.4.0 +default

Here we suggest default variant set, which includes most commonly used variants, if you need a minimum install, just remove the default variant set.

With tests:

$ phpbrew install --test 5.4.0

With debug messages:

$ phpbrew -d install --test 5.4.0

To install older versions (less than 5.3):

$ phpbrew install --old 5.2.13

Clean up build

$ phpbrew clean


PHPBrew arranges configure options for you, you can simply specify variant name, and phpbrew will detect include paths and build options for configuring.

PHPBrew provides default variants and some virtual variants, to the default variants, which includes the most commonly used variants, to the virtual variants, which defines a variant set, you may use one virtual variant to enable multiple variants at one time.

To check out what is included in these variants, simply run variants subcommand to list these variants:

$ phpbrew variants
  all, apxs2, bcmath, bz2, calendar, cgi, cli, ctype, dba, debug, dom, embed,
  exif, fileinfo, filter, fpm, ftp, gcov, gd, gettext, hash, iconv, icu,
  imap, intl, ipc, ipv6, json, kerberos, mbregex, mbstring, mcrypt, mhash,
  mysql, openssl, pcntl, pcre, pdo, pgsql, phar, posix, readline, session,
  soap, sockets, sqlite, tidy, tokenizer, xml_all, xmlrpc, zip, zlib

Virtual variants:
  dbs:      sqlite, mysql, pgsql, pdo
  mb:       mbstring, mbregex
  default:  filter, dom, bcmath, ctype, mhash, fileinfo, pdo, posix, ipc,
            pcntl, bz2, zip, cli, json, mbstring, mbregex, calendar, sockets, readline,

Using variants to build PHP:

  phpbrew install 5.3.10 +default
  phpbrew install 5.3.10 +mysql +pdo
  phpbrew install 5.3.10 +mysql +pdo +apxs2
  phpbrew install 5.3.10 +mysql +pdo +apxs2=/usr/bin/apxs2 

To enable one variant, simply add a prefix + before the variant name, eg


To disable one variant, simply add a prefix - before the variant name.


For example, if we want to build PHP with the default options and database supports (mysql, sqlite, postgresql), you may simply run:

$ phpbrew install 5.4.5 +default+dbs

You may also build PHP with extra variants:

$ phpbrew install 5.3.10 +mysql+sqlite+cgi

$ phpbrew install 5.3.10 +mysql+debug+pgsql +apxs2

$ phpbrew install 5.3.10 +pdo +mysql +pgsql +apxs2=/usr/bin/apxs2

To build PHP with pgsql (Postgresql) extension:

$ phpbrew install 5.4.1 +pgsql+pdo

Or build pgsql extension with postgresql base dir on Mac OS X:

$ phpbrew install 5.4.1 +pdo+pgsql=/opt/local/lib/postgresql91/bin

The pgsql path is the location of pg_config, you could find pg_config in the /opt/local/lib/postgresql91/bin

For more details, please check out PHPBrew Cookbook.

Extra Configure Options

To pass extra configure arguments, you can do this:

$ phpbrew install 5.3.10 +mysql +sqlite -- \
    --enable-ftp --apxs2=/opt/local/apache2/bin/apxs

Use And Switch

Use (switch version temporarily):

$ phpbrew use 5.4.22

Switch PHP version (switch default version)

$ phpbrew switch 5.4.18

Turn Off:

$ phpbrew off

List installed PHP

$ phpbrew list

The Extension Installer

You can also install PHP extension with ease, either the extensions shipped with PHP source code or even from PECL.

If the extension directory is found in PHP source, PHPBrew automatically switch into the PHP source directory and install the extension.

If the extension directory is not found in PHP source, PHPBrew fetch the extension package from PECL

PHPBrew also creates extension config to enable the installed extension, so you don't need to write the config file to enable it by hands. The extension config directory is in:


Installing Extension - The Most Simple Way

$ phpbrew ext install APC
$ phpbrew ext install memcache

Installing Extension With Version

To install extensions with stability tag:

$ phpbrew ext install xdebug stable
$ phpbrew ext install xdebug latest
$ phpbrew ext install xdebug beta

To install extensions with version name:

$ phpbrew ext install xdebug 2.0.1

To install extensions with customized options:

$ phpbrew ext install yaml -- --with-yaml=/opt/local

Enabling Extension

You can also install extension via PECL and enable it manually:

pecl install mongo
phpbrew ext enable mongo

The ext enable command allows you to create a config {current php base}/var/db/{extension name}.ini to enable the extension.

Configuring the php.ini for current php version

Simply run:

$ phpbrew config

You may specify the EDITOR environment variable to your favorite editor:

export EDITOR=vim
phpbrew config

Upgrade phpbrew

To upgrade phpbrew, you may simply run the self-update command, this command enables you to install the latest version of master branch from github:

$ phpbrew self-update

The Installed PHP(s)

The installed phps are located in ~/.phpbrew/php, for example, php 5.4.0RC7 is located at:


And you should put your configuration file in:


Extension configuration files should be put in:

... etc

Quick commands to switch between directories

Switching to PHP build directory

$ phpbrew build-dir

Switching to PHP dist directory

$ phpbrew dist-dir

Switching to PHP etc directory

$ phpbrew etc-dir

Switching to PHP var directory

$ phpbrew var-dir


phpbrew also provides useful fpm managing sub-commands. to use them, please remember to enable +fpm variant when building your own php.

To start php-fpm, simply type:

$ phpbrew fpm start

To stop php-fpm, type:

$ phpbrew fpm stop

To show php-fpm modules:

phpbrew fpm module

To test php-fpm config:

phpbrew fpm test

To edit php-fpm config:

phpbrew fpm config

The installed php-fpm is located in ~/.phpbrew/php/php-*/sbin.

The correspond php-fpm.conf is lcoated in ~/.phpbrew/php/php-*/etc/php-fpm.conf.default, you may copy the default config file to the desired location. e.g.,

cp -v ~/.phpbrew/php/php-*/etc/php-fpm.conf.default

php-fpm --php-ini {php config file} --fpm-config {fpm config file}

Installing Extra Component

Installing composer

$ phpbrew install-composer

Installing phpunit

phpbrew install-phpunit

Enabling Version Info Prompt

To add PHP version info in your shell prompt, you can use "PHPBREW_SET_PROMPT=1" variable.

The default is "PHPBREW_SET_PROMPT=0" (disable). To enable it, you can add this line to your ~/.bashrc file and put this line before you source ~/.phpbrew/bashrc.


To embed version info in your prompt, you can use current_php_version shell function, which is defined in .phpbrew/bashrc. and you can set the version info in your PS1 var. e.g.


Known Issues

  • For PHP-5.3+ versions, "Building intl 64-bit fails on OS X"

  • To build PHP with GD extension, you need to specify your libpng dir and libjpeg dir, for example,

    $ phpbrew install php-5.4.10 +default +mysql +intl +gettext +apxs2=/usr/bin/apxs2 \ -- --with-libdir=lib/x86_64-linux-gnu \ --with-gd=shared \ --enable-gd-natf \ --with-jpeg-dir=/usr \ --with-png-dir=/usr


Please see TroubleShooting


Q: How do I have the same version with different compile option?

A: Currently, you can install php5.x.x and rename the /Users/c9s/.phpbrew/php/php-5.x.x folder to the new name, for example, php-5.x.x-super , and install another php-5.3.3


Please see Contribution


Please see Wiki


Join us on #php-tw on


Yo-An Lin (c9s)


See LICENSE file.

Something went wrong with that request. Please try again.