subscribe: Posts | Comments

Setting up MAMP, PEAR, PECL, and PHPUnit on OSX Lion

Adding PHP to your PATH:

In your home directory, create or edit your existing.bash_profile and make sure it contains something like this:

export PATH=/Applications/MAMP/bin/php/php5.x.x/bin:/Applications/MAMP/Library/bin:$PATH

After making this change, restart your terminal. This will you to use simply use php from terminal. Test it by executing the commandphp --version from your home directory.

Also, execute the command which php and verify that it is pointing to the MAMP directory.

Setting up PECL

Note: Because the “MAMP Server Components” do not contain the source files for the latest PHP 5.3 release included with MAMP, I was forced to use PHP 5.3.5.

  1. Install X-Code from the App Store.
  2. Install the X-Code “command line tools” via the “Downloads” tab in the preferences pane.
  3. Download the MAMP Server Components
  4. mkdir /Applications/MAMP/bin/php/php5.x.x/include/php
  5. Within the MAMP Server Components archive you downloaded, you should see another archive containing the source for your PHP version. Extract all of the source into the directory you just created in step 4.
  6. cd /Applications/MAMP/bin/php/php5.x.x/include/php
  7. ./configure --enable-mbstring=all

We’re almost there! We need to manually install “Autoconf” before we can build PECL extensions. Here’s how:

  1. Download Autoconf
  2. Extract the files somewhere.
  3. Navigate to the place where you extracted the Autoconf files.
  4. ./configure; make; sudo make install

Alright! We’re finally ready to install an extension, so let’s give it a shot:

  1. pecl install mongo
  2. Add extension=mongo.so to/Applications/MAMP/bin/php/php5.x.x/conf/php.ini
  3. Edit your MAMP php.ini template (Edit Template -> PHP -> PHP 5.x.x php.ini), and add the same thing:extension=mongo.so.
  4. Restart your MAMP servers.
  5. Do a phpinfo() from a PHP script and verify the mongo extension is present.

Setting up PEAR and PHPUnit

First, make sure you have already added PHP to your path as described above. The rest is easy. Execute a which pear from your terminal and make sure it is pointing to MAMP. Great! Now, let’s do a simple pear upgrade pear to upgrade our PEAR installation. OK, now we’re ready to install PHPUnit:

  1. pear set-config auto_discover 1
  2. pear install pear.phpunit.de/PHPUnit

That’s it! Test it out by running the phpunit command from your terminal. You should see the available PHPUnit commands listed.