stupid simple PHP version management
Clone or download
Wil Moore III
Wil Moore III Merge pull request #68 from endelwar/endelwar-patch-1
Update php search regex
Latest commit 8d76a07 Apr 20, 2018
Failed to load latest commit information.
LICENSE General refactor Aug 26, 2013 Use https whenever possible Jan 16, 2018 added ini to bug report output Dec 7, 2013 Update php search regex Apr 20, 2018

simple PHP version switching

php-version exposes a php-version command allowing developers to switch between versions of PHP.

This IS for you if

  • You are not satisifed with heavy handed *AMP or PPA-based installers.
  • You use multiple versions of PHP on Linux or Mac.
  • You download pre-compiled PHP binaries for Windows.
  • You want to run your automated tests against multiple PHP versions.
  • You are a developer that works on a variety of PHP projects each requiring different versions of PHP.
  • You want to work on the latest PHP, but expect to support prior work that was done on older PHP versions.

This is NOT for you if

  • You are content with heavy handed *AMP installers.
  • You are provisioning a production server so you only need a single PHP install.
  • You NEVER work on more than one PHP project at a time.
  • You don't plan on supporting prior work that was done on other PHP versions.


php-version attempts to stick to the classic UNIX notion that tools should do one thing well.

While there are smart alternative tools that attempt to solve this problem, none of the tools I've found were simple enough for me.


  • Homebrew installed PHP versions are picked up automatically.
  • PHP versions installed into ~/.phps are picked up automatically.
  • PHP versions listed in the $PHP_VERSIONS shell variable are picked up automatically.
  • snap versioning: Use a partial version number (i.e. php-version 5) to automatically use the latest 5.x version.
  • per version php.ini: we export PHPRC if a version-specific php.ini exists.
  • configurable: php-version --help for details.
  • bash and zsh actively supported; though care has been taken such that other shells may work as well (but only bash and zsh are supported).
  • tiny: less than 150 LOC; a single function sourced via your shell's rc file.


  • no shims, sub-shells, symlinks or cd hooks.
  • we won't leave files and symlinks all over the place.
  • does not attempt to manage Apache, MySQL, etc.
  • does not attempt to compile, build, or install PHP.
  • does not attempt to support OS package manager installed (i.e. ppa, etc.) PHP versions.

Usage Examples

Switch to a specific PHP version

% php-version <version>

List installed and active (*) PHP version(s)

% php-version
* 5.4.8


homebrew (recommended for OSX users)

% brew tap homebrew/homebrew-php
% brew install php-version

cURL (for non-OSX users or those that prefer not to use homebrew):

% mkdir -p $HOME/local/php-version # or your place of choice
% cd !$
% curl -# -L | tar -xz --strip 1

Alternative (i.e. non-Homebrew) installation methods are documented on the wiki.


Add one of the following to $HOME/.bashrc, $HOME/.zshrc, or your shell's equivalent configuration file:

# Homebrew (recommended)
source $(brew --prefix php-version)/ && php-version 5

# non-Homebrew
source $HOME/local/php-version/ && php-version 5

Type php-version --help for more configuration options such as how to add extra PHP installation paths or php-config --version to find out which php version is active.

If you have PHP versions in multiple directories, you can list them in the environment variable PHP_VERSIONS separated by spaces as depicted below:

export PHP_VERSIONS="$HOME/local/php $HOME/php/versions"

NOTE: do this before you source

Deactivate / Uninstall

  1. Remove setup configuration.

  2. Enter one of the following commands listed below to remove associated files.

     # Homebrew (recommended)
     % brew remove --force php-version
     # non-Homebrew
     % rm -rf $HOME/local/php-version

Having Issues?

  1. Copy the bug report output to your clipboard (pbcopy works on Mac OSX; use your OS equivalent)

     % cd /tmp
     % git clone
     % source php-version/ | pbcopy
  2. File an issue.

More Info


99  Wil Moore III
 3  Jason P. Scharf
 3  Tugdual Saunier
 1  Gábor Egyed
 1  Martin Lundberg