Last Updated: 21 Nov 2020


Author: (external edit)

Installing PHPUnit on MAMP

Installing PHPUnit under MAMP can be a bit of a hassle. Here's what I did to install phpunit 3.6.11 under MAMP Pro 2.0.5.

  • MAMP, as you may know, has its own versions of PHP, PEAR, etc. These aren't related to the versions that Apple provides with OS X. MAMP's copies of these binaries live at /Applications/MAMP/bin/php/php5.2.17/bin. You'll want to install your PHPUnit there.
  • For some reason, there's an old config file that MAMP chokes on. At least there was on my install: mv /Applications/MAMP/bin/php/php5.2.17/conf/pear.conf /Applications/MAMP/bin/php/php5.2.17/conf/pear.conf.bak
  • First, you'll probably need to update PEAR:
    /Applications/MAMP/bin/php/php5.2.17/bin/pear channel-update
    /Applications/MAMP/bin/php/php5.2.17/bin/pear upgrade pear

    This should upgrade you to PEAR 1.9.4, or possibly a newer version.

  • Now it's time to add the appropriate PEAR channels for PHPUnit:
    /Applications/MAMP/bin/php/php5.2.17/bin/pear channel-discover
    /Applications/MAMP/bin/php/php5.2.17/bin/pear channel-discover
    /Applications/MAMP/bin/php/php5.2.17/bin/pear channel-discover
  • Finally, install PHPUnit:
    /Applications/MAMP/bin/php/php5.2.17/bin/pear install phpunit/PHPUnit
  • Test phpunit to make sure it was installed correctly:
     /Applications/MAMP/bin/php/php5.2.17/bin/phpunit --version
  • Technically, you're done now. However, its a real pain to access PHPunit by typing its full path, so I like to symlink it to phpunit in my path:
    sudo ln -s /Applications/MAMP/bin/php/php5.2.17/bin/phpunit /usr/local/bin/phpunit

That's it! If you have any questions or suggestions for improvements, post in the comments.


Enter your comment. Wiki syntax is allowed: