Skip to content

Extension Installer

ihipop edited this page Jan 12, 2017 · 20 revisions

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 http://pecl.php.net.

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 Proxy 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 show command. 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 pecl.php.net if it does not exists:

phpbrew ext show --download xhprof

You can also install an extension from GitHub:

phpbrew ext install https://github.com/c9s/cssmin.git

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

phpbrew --debug ext install https://github.com/c9s/cssmin.git

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

Cookbooks

Installing common extensions for PHP 5.x

phpbrew ext install apcu 4.0.11
phpbrew ext install yaml 1.3.0