PHPBrew
Read this in other languages: English, Português - BR, 日本語, 中文.
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, mysql, 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.
- 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.
- Path detection optimization for HomeBrew and MacPorts.
Requirement
Please see Requirement before you get started. you need to install some development packages for building PHP.
QUICK START
Please see Quick Start if you’re impatient. :-p
GETTING STARTED
OK, I assume you have more time to work on this, this is a step-by-step tutorial that helps you get started.
Move the file to some directory within your $PATH
sudo mv phpbrew.phar /usr/local/bin/phpbrew
Init a bash script for your shell environment:
```bash
phpbrew init
Add these lines to your .bashrc
or .zshrc
file:
[[ -e ~/.phpbrew/bashrc ]] && source ~/.phpbrew/bashrc
- Specifically for
fish
shell users, add following lines to your~/.config/fish/config.fish
file*:
source ~/.phpbrew/phpbrew.fish
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 preferred 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
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/php-src@PHP-7.2 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
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/libphp5.3.21.so
# LoadModule php5_module /usr/lib/httpd/modules/libphp5.3.20.so
The Extension Installer
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:
~/.phpbrew/php/5.4.20/bin/php
And you should put your configuration file in:
~/.phpbrew/php/5.4.20/etc/php.ini
Extension configuration files should be put in:
~/.phpbrew/php/5.4.20/var/db
~/.phpbrew/php/5.4.20/var/db/xdebug.ini
~/.phpbrew/php/5.4.20/var/db/apc.ini
~/.phpbrew/php/5.4.20/var/db/memcache.ini
... 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
PHP FPM
phpbrew also provides useful fpm managing sub-commands. to use them, please
remember to enable +fpm
variant when building your own php.
To setup the system FPM service, type one of commands:
# Typing the following command when systemctl is available in the Linux distribution.
$ phpbrew fpm setup --systemctl
# It is available in the Linux distribution.
$ phpbrew fpm setup --initd
# It is available in the macOS.
$ phpbrew fpm setup --launchctl
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 ~/.phpbrew/php/php-*/etc/php-fpm.conf php-fpm --php-ini {php config file} --fpm-config {fpm config file}