How to install PHP, PHPUnit and Composer on Mac OS X

Make sure the directories /usr/local, /usr/local/bin and /usr/local/sbin exist and check the permissions, so that regular users can access them. This should already be the case, if you got Homebrew installed and working.

Open _~/.bashprofile and check, if /usr/local/bin and _/usr/local/sbin_ are properly added to your PATH environment variable:

export PATH="/usr/local/sbin:/usr/local/bin:$PATH"

If there is no _~/.bashprofile yet, simply create it (see Mac OS X configuration for software developers).

Since using Homebrew seems overly complicated and you’ll get an outdated version (5.6.9 instead of 5.6.14 as of writing this), I recommend installing the binary package provided by Liip – thank you!

These commands will install the latest release of PHP 5.6 to /usr/local/php5:

# curl -s | bash -s 5.6
# cd /usr/local/bin
# ln -s /usr/local/php5/bin/php php
# ln -s /usr/local/php5/bin/phpize phpize
# ln -s /usr/local/php5/bin/php-config php-config
# php -v
PHP 5.6.14 (cli) (built: Oct 2 2015 08:55:56)
Copyright (c) 1997-2015 The PHP Group
Zend Engine v2.6.0, Copyright (c) 1998-2015 Zend Technologies
with Zend OPcache v7.0.6-dev, Copyright (c) 1999-2015, by Zend Technologies
with Xdebug v2.2.5, Copyright (c) 2002-2014, by Derick Rethans

If you prefer, you can choose to install other versions of PHP up to 7.0.

To download and install the current stable version of PHPUnit:

# wget
# chmod +x phpunit.phar
# mv phpunit.phar /usr/local/bin/phpunit
# phpunit --version
PHPUnit 5.0.8 by Sebastian Bergmann and contributors.

To download and install the latest version of composer:

# curl -sS | php
# chmod +x composer.phar
# mv composer.phar /usr/local/bin/composer
# composer -V
Composer version 1.0-dev (ef2856ef55715027ce2275f3b3bf1e84bfc778a4) 2015-10-29 22:35:30