With my recent acquisition of a new MacBook Pro, I needed to setup a fresh PHP development environment. I enjoy the convenience of MAMP Pro for managing virtual hosts, so I decided to give it a shot. Here’s how I got everything working:
Adding PHP to your PATH:
In your home directory, create or edit your existing
.bash_profile and make sure it contains something like this:
After making this change, restart your terminal. This will you to use simply use
php from terminal. Test it by executing the command
php --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.
Install X-Code from the App Store.
Install the X-Code “command line tools” via the “Downloads” tab in the preferences pane.
Download the MAMP Server Components
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.
We’re almost there! We need to manually install “Autoconf” before we can build PECL extensions. Here’s how:
Extract the files somewhere.
Navigate to the place where you extracted the Autoconf files.
./configure; make; sudo make install
Alright! We’re finally ready to install an extension, so let’s give it a shot:
pecl install mongo
Edit your MAMP
php.initemplate (Edit Template -> PHP -> PHP 5.x.x php.ini), and add the same thing:
Restart your MAMP servers.
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:
pear set-config auto_discover 1
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.