How to install PHPUnit with MAMP

Installing PHPUnit with MAMP’s PEAR installer is pretty straightforward, but there are a few things to note:

  1. Everything will be done through Terminal, so go ahead and launch it now. All of the commands I provide can be copied and pasted as they are.
  2. Make sure you’re using the version of PEAR that came with MAMP, not the version that came with your Mac. This means you have to use /Applications/MAMP/bin/php5/bin/pear at the prompt, not pear.
  3. PHPUnit 3.4 requires PHP 5.1.4 or later, but PHP 5.3.2 or later is recommended. MAMP 1.8.2 (the version I have installed) is running version 5.2.10. The latest version of MAMP includes version 5.3.2. So far, I haven’t noticed any problems running PHPUnit under 5.2.10.
  4. PHPUnit also requires PEAR 1.8.1. MAMP 1.8.2 ships with version 1.8.0. To check which version you have installed, type /Applications/MAMP/bin/php5/bin/pear -V.

If you need to upgrade PEAR, first use the following two commands: /Applications/MAMP/bin/php5/bin/pear channel-update
/Applications/MAMP/bin/php5/bin/pear upgrade pear

Now, it’s time to install PHPUnit. The PEAR channel used to distribute PHPUnit needs to be registered with the local PEAR environment and a component that PHPUnit depends upon is hosted on the Symfony Components PEAR channel. To register the channels and install, simply type: /Applications/MAMP/bin/php5/bin/pear channel-discover
/Applications/MAMP/bin/php5/bin/pear channel-discover
/Applications/MAMP/bin/php5/bin/pear install phpunit/PHPUnit

PHPUnit is now installed, but to get it to run from Terminal, we need to move it into our $PATH. To do so, type: mv /Applications/MAMP/bin/php5/bin/phpunit /usr/local/bin/phpunit.

To test your install, type: phpunit --version.

You should see something like PHPUnit 3.4.15 by Sebastian Bergmann. And that’s it!

31 thoughts on “How to install PHPUnit with MAMP

  1. Hi,

    Through (4) on your list I have at least the requirements (MAMP v1.9.2, PHP v5.3.2), except I cannot check pear.
    /Applications/MAMP/bin/php5.3/bin/pear -V (I added the 5.3) results in permission denied; prepending that with sudo I get command not found.

    Same thing (including command not found result) happen when I try the channel-update line.

    What I’m trying to accomplish is to add a debugger to the Eclipse for PHP Developers IDE on my OS-X v10.6.4 machine…

  2. You’ll also need to setup the channel:

    /Applications/MAMP/bin/php5/bin/pear channel-discover

    Not sure when this became required, but phpunit wouldn’t install for me until I ran that command.

  3. David O is right. You’ll need to run this
    /Applications/MAMP/bin/php5/bin/pear channel-discover
    before you run the install. Otherwise when you try and move phpunit you’ll find that it’s not there. It works fine if you go back and reinstall though

  4. i found that i needed to symlink php5.3 to php5 for updates to work.

    ln -s /Applications/MAMP/bin/php5.3 /Applications/MAMP/bin/php5

    and then instead of moving phpunit.. ln -s /Applications/MAMP/bin/php5/bin/phpunit /usr/local/bin/phpunit

  5. I’m having issues with this. Can you help, please? When I run phpunit –version, I get the following returned:
    -bash: /Applications/MAMP/bin/php5.3/bin/phpunit: /Applications/MAMP/bin/php5/bin/php: bad interpreter: No such file or directory

    I’ve tried creating the symbolic link from above, ln -s /Applications/MAMP/bin/php5.3 /Applications/MAMP/bin/php5, with no luck. Any help would be appreciated. Thanks, PDB

      • I know this was a long time ago, but do you remember if you did anything else to solve this? my phpunit file has the correct directories, but is still giving me the error.
        Thanks in advance

  6. Pingback: Teleogistic / Setting up PHPUnit with MAMP

  7. For my installation this line was incorrect:

    /Applications/MAMP/bin/php/php5.4.4/bin/pear channel-discover

    When trying to install it required another channel, with the correct command being:

    /Applications/MAMP/bin/php/php5.4.4/bin/pear channel-discover

    Tyler$ /Applications/MAMP/bin/php/php5.4.4/bin/pear channel-discover

    Discovering channel over http:// failed with message: channel-add: Cannot open “” (File not valid (received: HTTP/1.1 403 Forbidden))

    Trying to discover channel over https:// instead
    Discovery of channel “” failed (channel-add: Cannot open “” (Connection to `′ failed: Connection refused))

  8. Thanks – this worked great for me.

    I had installed PhpUnit following other steps (trying to use Kenjis phpunit for CodeIgniter (, but realized I wanted to easily connect and test against a MAMP’s database, at least when working locally.

    Note: Because I now have both phpUnits installed, I aliased this one to ‘mamp_phpunit':
    ln -s /Applications/MAMP/bin/php/php5.4.4/bin/phpunit ~/bin/mamp_phpunit

  9. Don’t MOVE phpunit to your path, instead add the MAMP bin dir to your PATH. That will work far nicer than moving binaries around. something like:

    export PATH=/Applications/MAMP/Library/bin/:/Applications/MAMP/bin/php/php5.3.6/bin/:/opt/local/bin:/opt/local/sbin:$PATH

    replace php5.3.6 with your bin path.

  10. Pingback: How to install phpunit under OSX 10.8.4 with MAMP 2.1.4 for Yii and Netbeans? | BlogoSfera

  11. Pingback: Install PEAR on MAMP - PHP Solutions - Developers Q & A

  12. Hi, I have a problem with de last line:
    mv /Applications/MAMP/bin/php5/bin/phpunit /usr/local/bin/phpunit
    the answer is:
    mv: rename /Applications/MAMP/bin/php/php5.5.3/bin/phpunit to /usr/local/bin/phpunit: Permission denied
    Any idea? Thanks

    • add the word “sudo” (Super-user do) which allows a “user” root permissions. so: mv /Applications/MAMP/bin/php5/bin/phpunit /usr/local/bin/phpunit

  13. Pingback: Installing PHPUnit on Mac OS 10.7 w/ MAMP | Mitchell Fang's Coding

  14. Pingback: Zend installation on MAMP version 2 | Joan Healy

  15. add the word “sudo” (Super-user do) which allows a “user” root permissions. so: sudo mv /Applications/MAMP/bin/php5/bin/phpunit /usr/local/bin/phpunit

  16. Pingback: EchoNest Explorations | Media Zoo

  17. Pingback: The First Green Light: Recap – continuousintegrationblog

Leave a Reply