Installing PHPUnit on OS X using MAMP via PEAR

Here is a quick and solid way to add PHPUnit to your MAMP Setup


The path to your PHP and PEAR if you are using MAMP is something similar to this





notice the this will depend on the version of php you are using, in my case is php5.3.6 so have that in mind if you are planning on copy pasting this guide


  1. Turn on PEAR auto discover
    /Applications/MAMP/bin/php/php5.3.6/bin/pear config-set auto_discover 1

    As Alex from the comments states you might need to update pear
    cd /Applications/MAMP/bin/php/php5.3.6/bin
    sudo ./pear upgrade pear

  2. Install PHPUnit from
    /Applications/MAMP/bin/php/php5.3.6/bin/pear install will install PHPUnit under
  3. If done right the phpunit file should already contain reference to the MAMP’s php you are choosing to use, now to have phpunit available on your system as a command you can do something similar to this:
    sudo ln -s /Applications/MAMP/bin/php/php5.3.6/bin/phpunit /usr/local/bin/phpunit

I always try to keep my binaries and executables under /usr/local/bin but this is my choice you can try some other directory as long as you have it exposed on via your EXPORTS

  • Alex

    If you installation of PHPUnit doesn’t work it is most likely because pear is out of date.

    Just run:

    cd /Applications/MAMP/bin/php/php5.3.6/bin
    sudo ./pear upgrade pear

    before step 1 of the instructions to be safe.

    This was my case under Lion with MAMP PRO 2.0.5 installed.

  • admin

    Thanks Alex, I’ll update

  • Pingback: ew | MAMP PRO Pear Installation

  • Steve

    Kudos to you! Out of all the crazy ass instructions i found, this is by far the most coherent and simple.

    An issue I ran into was when running phpunit it wouldn’t output anything. I actually had to edit the phpunit executable file in /Applications/MAMP/bin/php/php5.4.4/bin and change @php_bin@ to the directory where the phpunit files.

    I just downloaded the zip from the site and put the PHPUnit folder in:


    Then changed the string in the phpunit exec. to: