Skip to content

Instantly share code, notes, and snippets.

@soifou
Last active September 8, 2021 18:08
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save soifou/404b4403b370b6203e6d145ba9846fcc to your computer and use it in GitHub Desktop.
Save soifou/404b4403b370b6203e6d145ba9846fcc to your computer and use it in GitHub Desktop.
PHPBrew - Manage PHP versions efficiently

PHPBrew

Dependencies

$ apt-get install -y \
    autoconf automake curl libcurl3-openssl-dev build-essential libxslt1-dev \
    re2c libxml2 libxml2-dev bison libbz2-dev libreadline-dev \
    libfreetype6 libfreetype6-dev libpng12-0 libpng12-dev libjpeg-dev libjpeg8-dev \
    libjpeg8  libgd-dev libgd3 libxpm4 libltdl7 libltdl-dev \
    libmhash-dev libmhash2 libssl-dev openssl \
    gettext libgettextpo-dev libgettextpo0 \
    libmcrypt-dev libmcrypt4 libicu-dev

Installation

$ curl -L -O https://github.com/phpbrew/phpbrew/raw/master/phpbrew
$ chmod +x phpbrew
$ mv phpbrew /usr/local/bin/phpbrew

Init PHPBrew (first time only)

$ phpbrew init

Export some PHPBrew vars in your current shell (.zshrc or .bashrc)

export PHPBREW_ROOT="$HOME/.phpbrew"
if [ -d "${PHPBREW_ROOT}" ]; then
    export PHPBREW_SET_PROMPT=1
    export PHPBREW_RC_ENABLE=1
    source $PHPBREW_ROOT/bashrc
fi

Reload your current shell

$ source .zshrc

Play with PHP versions

Check available extension

$ phpbrew variants

Install specific few PHP versions with some extensions

$ phpbrew install 5.6.20 +default +iconv +icu +intl +mysql +xml_all
$ phpbrew install 7.0.5 +default +iconv +icu +intl +mysql +xml_all

To use the newly built PHP, try the line(s) below:

$ phpbrew use php-5.6.20

You can use switch command to switch your default php to php-5.6.20:

$ phpbrew switch php-5.6.20

Configure your current PHP ini file if needed

$ phpbrew config

Deal with the web server

If you install apache2 as webserver and don't want to use PHP-FPM, you must install an extra PHP extension.

$ phpbrew install X.Y.Z +apxs2=/usr/bin/apxs2

See for more details: http://stackoverflow.com/questions/20584156/tell-apache-to-use-a-specific-php-version-installed-using-phpbrew

Else you have to install PHP-FPM extension

$ phpbrew install X.Y.Z +fpm

With PHP-FPM, you have additional command available:

# phpbrew fpm [start|stop|restart|module|test|help|config]
$ phpbrew fpm config
$ phpbrew fpm test
$ phpbrew fpm start

Be warn you have to fpm stop before switching to another PHP-FPM version. Here is the workflow:

$ cd myproject
$ phpbrew list
$ phpbrew use php-5.6.20
$ phpbrew fpm start
... dev ...
$ phpbrew fpm stop
$ phpbrew list
$ phpbrew use php-7.0.5
$ phpbrew fpm start
... dev ...

Enable autocompletion for zsh

$ cd /usr/local/share/zsh-completions
$ curl -O https://raw.github.com/c9s/phpbrew/master/completion/zsh/_phpbrew
$ exec zsh
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment