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

What phpbrew can do for you:

  • Configure options are simplified into variants, no worries about the path anymore!
  • Build php with different variants like PDO, , sqlite, debug …etc.
  • Compile apache php module and separate them by different versions.
  • Build and install php(s) in your home directory, so you don’t need root permission.
  • 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.
  • Path detection optimization for HomeBrew and MacPorts.


These requirements are for you to run phpbrew and build your PHP. To build your PHP, you need a lot of libraries installed on your system.

The instructions below help you to get things done. Please note that this document may not apply to the versions still under development, and you may need to install some libraries which are not listed here for certain extensions.

Platform support


  • PHP5.3+
  • curl
  • gcc, binutils, autoconf, libxml, zlib, readline


curl -L -O
chmod +x phpbrew

# Move phpbrew to somewhere can be found by your $PATH
sudo mv phpbrew /usr/local/bin/phpbrew


If you’re impatient, you can follow the following steps to get things ready.


phpbrew init

# I assume you're using bash
echo "[[ -e ~/.phpbrew/bashrc ]] && source ~/.phpbrew/bashrc" >> ~/.bashrc

# For the first-time installation, you don't have phpbrew shell function yet.
source ~/.phpbrew/bashrc

# Fetch the release list from official php site...
phpbrew update

# List available releases
phpbrew known

# List available variants
phpbrew variants

# Let's brew something out.
phpbrew --debug install --stdout 7.0 as 7.0-dev +default +intl -- # put your extra configure options here, e.g. --with-readline=...
# --debug and --stdout are useful for debugging if the configure script encountered some problems
# the first "7.0" will be expanded to 7.0.7 (the latest release) and 7.0-dev will be the build name that you use to switch versions.
# extra configure option is optional.

# Set 7.0-dev as default php and switch to it.
phpbrew switch 7.0-dev

# Install some extensions for php7, please note the command below are for php7
phpbrew --debug ext install xdebug 2.4.0
phpbrew --debug ext install github:krakjoe/apcu
phpbrew --debug ext install github:php--dev/php- php7 -- ----sasl
phpbrew --debug ext install github:phpredis/phpredis php7

# Install php 5.6 with the same variant options like 7.0
phpbrew install 5.6 as 5.6-dev like 7.0-dev


OK, I assume you have more time to work on this, this is a step-by-step tutorial that helps you get started.

Setting up

Init a bash script for your shell environment:

phpbrew init

Add these lines to your .bashrc or .zshrc file:

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

For fish shell users, add following lines to your ~/.config/fish/ file:

source ~/.phpbrew/

If you’re using system-wide phpbrew, you may setup a shared phpbrew root, for example:

mkdir -p /opt/phpbrew
phpbrew init --root=/opt/phpbrew

Setting up lookup prefix

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

For Homebrew users:

phpbrew lookup-prefix homebrew

For Macports users:

phpbrew lookup-prefix macports


To list known versions:

phpbrew known

7.0: 7.0.3, 7.0.2, 7.0.1, 7.0.0 ...
5.6: 5.6.18, 5.6.17, 5.6.16, 5.6.15, 5.6.14, 5.6.13, 5.6.12, 5.6.11 ...
5.5: 5.5.32, 5.5.31, 5.5.30, 5.5.29, 5.5.28, 5.5.27, 5.5.26, 5.5.25 ...
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 ...
5.3: 5.3.29, 5.3.28 ...

To show more minor versions:

$ phpbrew known --more

To update the release info:

$ phpbrew update

To get older versions (less than 5.4)

Please note that we don’t guarantee that you can build the php versions that are not supported by offical successfully, please don’t fire any issue about the older versions, these issues won’t be fixed.

$ phpbrew update --old

To list known older versions (less than 5.4)

$ phpbrew known --old

Starting Building Your Own PHP

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.

You can enable parallel compilation by passing -j or --jobs option and the following is an example:

$ phpbrew install -j $(nproc) 5.4.0 +default

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

To install the latest patch version of a given release:

$ phpbrew install 5.6

To install a pre-release version:

$ phpbrew install 7.2.0alpha1
$ phpbrew install 7.2.0beta2
$ phpbrew install 7.2.0RC3

To install from a GitHub tag or branch name:

$ phpbrew install github:php/[email protected] as php-7.2.0-dev

To install the next (unstable) version:

$ phpbrew install next as php-7.3.0-dev

Cleaning up build directory

$ phpbrew clean php-5.4.0


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, curl, dba, debug, dom,
  dtrace, editline, embed, exif, fileinfo, filter, fpm, ftp, gcov, gd,
  gettext, gmp, hash, iconv, icu, imap, inifile, inline, intl, ipc, ipv6,
  json, kerberos, libgcc, mbregex, mbstring, mcrypt, mhash, mysql, opcache,
  openssl, pcntl, pcre, pdo, pgsql, phar, phpdbg, posix, readline, session,
  soap, sockets, sqlite, static, tidy, tokenizer, wddx, xml, xml_all, xmlrpc,
  zip, zlib, zts

Virtual variants:
  dbs:        sqlite, mysql, pgsql, pdo

  mb:         mbstring, mbregex


  small:      bz2, cli, dom, filter, ipc, json, mbregex, mbstring, pcre, phar,
              posix, readline, xml, curl, openssl

  default:    bcmath, bz2, calendar, cli, ctype, dom, fileinfo, filter, ipc,
              json, mbregex, mbstring, mhash, mcrypt, pcntl, pcre, pdo, phar,
              posix, readline, sockets, tokenizer, xml, curl, openssl, zip

  everything: dba, ipv6, dom, calendar, wddx, static, inifile, inline, cli,
              ftp, filter, gcov, zts, json, hash, exif, mbstring, mbregex,
              libgcc, pdo, posix, embed, sockets, debug, phpdbg, zip, bcmath,
              fileinfo, ctype, cgi, soap, pcntl, phar, session, tokenizer,
              opcache, imap, tidy, kerberos, xmlrpc, fpm, dtrace, pcre, mhash,
              mcrypt, zlib, curl, readline, editline, gd, intl, icu, openssl,
              mysql, sqlite, pgsql, xml, xml_all, gettext, iconv, bz2, ipc, gmp

Using variants to build PHP:

  phpbrew install php-5.3.10 +default
  phpbrew install php-5.3.10 +mysql +pdo
  phpbrew install php-5.3.10 +mysql +pdo +apxs2
  phpbrew install php-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

To build PHP with neutral compile options, you can specify neutral virtual variant, which means that phpbrew doesn’t add any additional compile options including --disable-all. But some options(for example --enable-libxml) are still automatically added to support pear installation. You can build PHP with neutral:

$ phpbrew install 5.4.1 +neutral

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

If you enable apache PHP modules, remember to comment out or remove the settings.

$ sudo vim /etc/httpd/conf/httpd.conf
# LoadModule php5_module        /usr/lib/httpd/modules/
# LoadModule php5_module        /usr/lib/httpd/modules/

The Extension Installer

By using phpbrew, 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:

~/.phpbrew/php/{build name}/var/db

Installing Extension – The Most Simple Way

Before you install any PHP extension, you should set your current running php:

phpbrew use php-5.5.6

Then run ext install to install the extensions

phpbrew ext install apcu 4.0.11
phpbrew ext install memcached 1.0.2
phpbrew ext install xdebug 1.3.2

Please note that you need to specify the extension version to support php5/php7, in this case, apcu 4.0.11 and memcached 1.0.2 are required for php5.6.

See also:

Installing Extension With Stability

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

Install extensions with customized options:

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

Installing Extension from GitHub

The special prefix github: tells phpbrew to get the extension repository from php-memcached-dev/phpmemcached and branch php7

$ phpbrew ext install github:php-memcached-dev/php-memcached php7 -- --disable-memcached-sasl

Installing Extension with specific downloader

Right now, phpbrew supports 4 different downloader implementation:

  • php_curl – download files using the built-in php curl extension.
  • php_stream – download files using the built-in php stream wrapper.
  • curl
  • wget

It’s possible to replace the default downloader with your preference:

phpbrew ext install --downloader php_curl apcu

The curl php extension based downloader supports User-Agent and Settings, thus you can do this if you encountered some network issues:

phpbrew ext install --downloader php_curl --http-proxy=... --http-proxy-auth=... apcu

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.

Showing extension config options

To see if there are some configure options to build the extension, you can use the ext showcommand. Please note that the show command only works for built-in extensions:

phpbrew ext show gmp

Which will show you the detailed information of gmp extension:

                Name: gmp
    Source Directory: /Users/c9s/.phpbrew/build/php-5.5.17/ext/gmp
              Config: /Users/c9s/.phpbrew/build/php-5.5.17/ext/gmp/config.m4
            INI File: /Users/c9s/.phpbrew/php/php-5.5.17/var/db/gmp.ini
           Extension: Core
                Zend: no
              Loaded: no

   Configure Options:

        --with-gmp[=DIR]                 for GNU MP support

To use the configure option for your installation, you may append the configure option after a --separator:

phpbrew ext install gmp -- --with-gmp=/opt/local

To see the details of a Pecl extension that is not downloaded yet, you may specify --download to download the extension from if it does not exists:

phpbrew ext show --download xhprof

You can also install an extension from GitHub:

phpbrew ext install

To see more detailed output of the installation, you may add --debug option to the command

phpbrew --debug ext install

To list the installed / loaded extension:

phpbrew  ext --show-options --show-path

To clean up the source diretory:

phpbrew ext clean opcache

And the --purge option will remove the whole directory of the extension directory:

phpbrew ext clean --purge opcache   # Delete whole extension source directory

Fedora/Centos 64-Bit

Passing -- --with-libdir=lib64 may be required in some cases. Ex:

phpbrew ext install ldap -- --with-libdir=lib64


Installing common extensions for PHP 5.x

phpbrew ext install apcu 4.0.11
phpbrew ext install yaml 1.3.0

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)

To list all installed php(s), you could run:

$ phpbrew list

The installed phps are located in ~/.phpbrew/php, for example, php 5.4.20 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 located 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 Apps

phpbrew provides app command to fetch some php apps.

Installing composer

$ phpbrew app get composer

Installing phpunit

phpbrew app get 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 phpbrew_current_php_version shell function, which is defined in .phpbrew/bashrc. and you can set the version info in your PS1 var. e.g.

PS1=" \$(phpbrew_current_php_version) \$ "

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--gnu

Please see TroubleShooting


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

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


Please see Wiki


Please see PHPBrew

Print Friendly, PDF & Email



Bài viết liên quan