2 min read

Pear, & phpUnit with Mamp Pro

Now updated for MAMP 2.0.1

I like using MAMP Pro on my mac because it is so easy to setup and the included virtual hosts are very nice. Plus it is easy to install for designers and those that don’t like mucking in the file system.

One gotcha though is installing php, pear, and then phpunit so it will run through terminal.  I know that there are tons of tutorials on this but from my recent research finding the exact steps hasn’t been very simple. (Plus some of them are just strange ways of doing it imo) So I decided I should write out a post describing all the steps to get this setup and have this for future reference
After you have mamp pro installed open terminal and follow these steps…

1. Backup old files. (just incase)

sudo mv /usr/bin/php /usr/bin/php_bak
sudo mv /usr/bin/pear /usr/bin/pear_bak
sudo mv /usr/bin/phpunit /usr/bin/phpunit_bak

2. Symlink the mamp “php” and “pear” file

sudo ln -s /Applications/MAMP/bin/php/php5.3.6/bin/php /usr/bin/php
sudo ln -s /Applications/MAMP/bin/php/php5.3.6/bin/pear /usr/bin/pear

3. Update pear info

sudo pear config-set  doc_dir /Applications/MAMP/bin/php/php5.3.6/lib/php/doc
sudo pear config-set  ext_dir /Applications/MAMP/bin/php/php5.3.6/lib/php/extensions
sudo pear config-set  php_dir /Applications/MAMP/bin/php/php5.3.6/lib/php/
sudo pear config-set  php_bin /Applications/MAMP/bin/php/php5.3.6/bin/php
sudo pear config-set  php_ini /Applications/MAMP/bin/php/php5.3.6/conf/php.ini
sudo pear config-set  sig_keydir /Applications/MAMP/bin/php/php5.3.6/pearkeys
# This fixes a bug in pear
sudo rm /Applications/MAMP/bin/php/php5.3.6/conf/pear.conf 

4. Upgrade pear

sudo pear channel-update pear.php.net
sudo pear upgrade pear
pear -V
PEAR Version: 1.9.4
PHP Version: 5.3.6

5. Install phpUnit

sudo pear channel-discover pear.phpunit.de
sudo pear channel-discover components.ez.no
sudo pear channel-discover pear.symfony-project.com
sudo pear install --alldeps phpunit/PHPUnit

6. Move “phpunit” to /usr/bin

sudo ln -s  /Applications/MAMP/bin/php/php5.3.6/bin/phpunit /usr/bin/phpunit</pre>

7. Optionally Install vfStream:

sudo pear channel-discover pear.php-tools.net
sudo pear install pat/vfsStream-alpha

That should be it. At this point php, pear, and phpunit should all work via terminal.

Errors

If you get this error: Notice: unserialize(): Error at offset 276 of 1133 bytes in Config.php on line 1050 ERROR: The default config file is not a valid config file or is corrupted.

Try removing this file:

sudo rm /Applications/MAMP/bin/php/php5.3.6/conf/pear.conf