phpfarm is a set of scripts to install a dozen of PHP versions in parallel on a single system. It also installs the pear and pyrus installers and creates a local Pyrus installation for each PHP version as well.
This tool was primarily developed for PEAR's continuous integration machine.
The PHP source packages are fetched from http://museum.php.net/ (which is not always up-to-date), the official php.net download pages and the pre-release channels.
The Pyrus PHAR archive is fetched from http://pear2.php.net/pyrus.phar (which always refers the latest version).
Last but not least, phpfarm can automatically apply the Suhosin patch for the version of PHP you are installing. It does so by looking at http://www.hardened-php.net/suhosin/download.html for compatible versions of the patch.
If a file cannot be found, try to fetch it manually and put it into
- Check out phpfarm from git:
git clone git://git.code.sf.net/p/phpfarm/code phpfarm
- PHP gets installed into
phpfarm/inst/bin/php-$versionis also executable You should add
Configure options customization
Default configuration options are in
You may create version-specific custom option files:
The shell script needs to define a variable "
Do not try to change
php.ini values may also be customized:
Please note that a few substitutions are done in those files in order to generate the final php.ini configuration file. Namely, the following variables are substitued:
$ext_dirgets replaced by the path to the extension directory This is mostly used to set the
extension_diroption to the right value. This is also useful when installing a
zend_extensionlike Xdebug as
extension_diris not automatically prepended to the path for those extensions.
You may also create version-specific scripts that will be run after the PHP binary has been successfully compiled, installed and configured:
These scripts can be used for example to discover PEAR channels and pre-install some extensions/packages needed by your project.
Each script is called with three arguments:
- The PHP version that was just installed (eg.
- The full path to the folder where that version was install
- The full path to the shared folder containing the links to the main
executables for each version (eg.
You do not need to specify a "shebang line" (
#!...) at the beginning
of the scripts. Bash will always be used to execute them.
Given all the previous bits of information, the following shell script may be used to discover a PEAR channel and install a PEAR extension:
# "$3/pear-$1" could also be used in place of "$2/bin/pear" to refer # to the pear installer for this specific version of PHP. "$2/bin/pear" channel-discover pear.phpunit.de "$2/bin/pear" install pear.phpunit.de/PHPUnit # The exit status must be 0 when the scripts terminates without any error. # Any other value will be treated as an error. exit 0
Your post-install customization script should always exit with a zero status when they terminate normally. Any other value will be considered a failure and will make phpfarm exit immediately with an error.
Special flags in version strings
phpfarm recognizes a few special flags in the version string. These flags must be appended to the version string and separated from it and from one another by dashes (-).
The following flags are currently accepted:
debugto compile a version with debugging symbols.
ztsto enable thread safety.
32bitsto force the creation of a 32 bits version of PHP on a 64 bits machine.
gcovto enable GCOV code coverage information (requires LTP).
suhosinto apply the Suhosin patch before compiling PHP. This patch provides several enhancements to build an hardened PHP binary.
suhosin flag only applies the Suhosin patch. It does not
automatically install the Suhosin extension. If you want to benefit
from the whole set of attack mitigation techniques provided by Suhosin,
you must also install the Suhosin extension separately (and manually),
using a post-install script
For example, to build a thread-safe version of PHP 5.3.1 with debugging symboles, use:
The order in which the flags appear does not matter, phpfarm will
reorganize them if needed. Hence,
5.3.1-zts-debug is effectively
the same as
You may actually compile and install several versions of PHP in turn
by passing the name of each version to
./main.sh 5.3.1 5.4.0beta1
You may also create a file called
which contains the names of the versions (one per line) you want
installed by default.
Empty lines are ignored in this file. Lines starting with a hash (#)
are treated as comments and also ignored.
This file will be used by
./main.sh when it's called without any
argument and is mostly useful when you often need to recompile the same
versions of PHP (eg. as part of a Continuous Integration process).
It generally looks somewhat like this:
# Generic version used for dev. 5.3.1 # Beta version used to test for regressions # and to report bugs to the PHP folks. 5.4.0beta1 # Custom version which installs specific extensions/packages # required for production during the post-install step. 5.3.1-prod
Last but now least, when using a
the first version in this file will be marked as your "main version".
So, if phpfarm's
inst/main directory is in your
$PATH and there
php executable installed globally on your system, calling
php will actually execute your main version's
The following entries are known issues which may or may not be solved in the future:
- Do not use
--enable-sigchldin your custom options if you plan to install extensions using pear/pecl. When enabled, this option will result in a failure during the
phpizestep (this issue lies in PHP itself and is not specific to phpfarm).
- By default, a (local) PEAR installation is created for every PHP version
you build. If you don't plan to use PEAR, you can prevent this from
happening by adding