Installing PHPUnit under PHP 5.4 from Homebrew

On my mac, I use Jose Gonzales’ homebrew tap for installing PHP 5.4. It works amazingly well, generating apache modules and FPM plists for every version in case I need them, as well as the CLI version.

Unfortunately, it also means that all of you pear extensions are installed under your PHP 5.4 install, meaning that you have to do a bit of work to get it all working. Here are the steps I followed:

Install PHPUnit

sudo pear channel-discover
sudo pear channel-discover
sudo pear install --alldeps phpunit/phpunit

Configure your PHP include path

Edit your php.ini to set up your include path, it’s normally at /usr/local/etc/php/5.4/php.ini (or run php -i to see).

Search for include_path and add the path /usr/local/Cellar/php54/5.4.7/lib/php/. It should look something like this:


Note that you might need to change 5.4.7 to whatever version of PHP you have installed. Run php -v to find out.


Open a new terminal window and type phpunit – things should be working fine

Michael is a polyglot software engineer, committed to reducing complexity in systems and making them more predictable. Working with a variety of languages and tools, he shares his technical expertise to audiences all around the world at user groups and conferences. You can follow @mheap on Twitter

Thoughts on this post

nXqd 2013-01-07

You have to add the path of php library:


michael 2013-01-07

Thanks for mentioning in case others have the same issue. This is actually documented in the README for the homebrew recipe. A better way to add to your path is to use the following line:

export PATH="$(brew --prefix josegonzalez/php/php54)/bin:$PATH"

Lapp 2013-03-05

Wouldn’t it be more homebrewey to symlink the phpunit executable to /usr/local/bin ?

michael 2013-03-06

It would, but I’m not sure if that would work. PHPUnit includes a lot of extra files itself, and if the include path is not set up it might not be able to find them (e.g. the File Iterator, or any DBUnit tests)

troelskn 2013-04-25

FWIW I did this and have had no issues. It looks like the phpunit executable includes its dependencies by absolute paths, so it’ll probably be fine.

Mark 2013-01-16

Thanks for the info. Appreciated.

TeMc 2013-01-24

It looks like right now (php 5.4.11 from josegonzalez/homebrew-php) the path to /usr/local/Cellar/php54/5.4.7/lib/php/ is in PHP’s include_path by default.

The default php.ini in /usr/local/etc/php/5.4/php.ini has “include_path” commented out (with “;”). But somehow it automatically includes this directory at run time.

Verified by the following command, ran right after “brew install php54”:

$ which php && readlink `which php` && php -r ‘echo get_include_path();’



bitbox67Thibaut 2013-03-13

To avoid further modification of the php.ini file, you could use:

; php54 libraries

In the /usr/local/etc/php/5.4/php.ini file.

As /usr/local/opt/php54 is symlinked to your latest Homebrewed php54 install, it should get updated whenever you issue a brew upgrade (or specifically install a new brewed version of php54). This means, of course, that you may have to re-execute the 3 pear commands outlined above after the upgrade…

Also, it might be important to note that, to make sure you are effectively executing the Homebrewed version of php (as well as some other executables installed with Homebrew) it is necessary to update your ~.bash_profile configuration. Add this:

# Homebrew PHP54
export PATH=”$(brew –prefix josegonzalez/php/php54)/bin:$(brew –prefix josegonzalez/php/php54)/lib/php:$PATH”
# update PATH for Homebrew
export PATH=/usr/local/bin:/usr/local/sbin:$PATH

(after making those changes you should then open a new terminal window to have your updated ~.bash_profile used in the CLI)

To verify that everything works as expected, type

php -v

in the command line, the displayed version number should then fit your homebrewed version, which will most probably be more recent than the OS X packaged one.

Hope this may help some avoid loosing some hairs trying to figure out what php is effectively running 😉

cordoval 2013-04-13

thanks a lot, i was able to do it

Nilo Cesar Teixeira 2013-04-23

It worked after the PATH modification, thank you!

Sean Fisher 2013-05-17

Try running “brew unlink php54 && brew link php54” after installing PHPUnit. This will let homebrew create a symlink from all the files in the bin folder to the main homebrew bin folder. No need to modify $PATH then.

Unit tests voor WordPress plugins | Remco Tolsma 2013-06-05

[…] […]

Upgrading PHP with Homebrew « Haydn Williams 2013-09-15

[…] Check that the last command found a binary in a directory relating to the new version of PHP, e.g. /usr/local/opt/php55/bin. Note that /usr/local/opt/php5 is just a symlink to /usr/local/Cellar/php5<X>/5.<X>.<X> More info… […]

Dan Fare 2014-11-14

Thanks for the post,

Leave a comment?

Leave a Reply