Install PEAR on MAMP

Colin Martin picture Colin Martin · Apr 1, 2011 · Viewed 16.7k times · Source

I am using MAMP for development. I have never been able to get PEAR to work. The MAMP documentation and forums seem not to have the answers. Everybody who asked on the MAMP forum seems to have no replies.

Previously I have developed the systems on MAMP and only used PEAR for mail so I got it working once on the server rather than in MAMP. I want to use more of PEAR now.

Can anybody give me an idiots guide to getting it going. I can access terminal and type command lines, however, I don't really understand what's going on so when things stop or throw errors I have to ask more questions. I have had a go with various things found on the internet but failed so far.

MAMP is version 1.9.5 Mac OS 10.6.7

Answer

zechdc picture zechdc · Nov 18, 2011

@Marcelo Rodrigo's answer is great! And I'm glad he included his sources. By following sources of his sources I was able to find the information below.


Install PEAR on MAMP

In order to get PEAR working with MAMP run the following commands. Notice there are commands for MAMP v1.x.x and for newer versions. Find out what version you are running. Also, notice that the PHP versions differ. Make sure the version in the commands below is the one you are actually using. MAMP allows you to change versions. You can check by opening MAMP > Server > PHP.

NOTE:

This may be obvious to some, but you should stop MAMP first. Otherwise you might get some strange errors.

1) Change the directory permissions so you can execute files within them:

MAMP v2.x.x

chmod 774 /Applications/MAMP/bin/php/php5.4.4/bin/pear
chmod 774 /Applications/MAMP/bin/php/php5.4.4/bin/php

MAMP v1.x.x

chmod 774 /Applications/MAMP/bin/php5.3/bin/pear
chmod 774 /Applications/MAMP/bin/php5.3/bin/php

2) Setup an alias to avoid typing the whole path.

Every time you want to access pear you have to type "/Applications/MAMP/bin/php5.3/bin/pear". Typing "pear" referes to what is installed on your mac already and not MAMP's install. (This only apply for the current session. For a permanent alias, place the command below in your ~/.bash_profile file. Here is a tutorial on how to do that.)

MAMP v2.x.x

alias mpear="/Applications/MAMP/bin/php/php5.4.4/bin/pear"

MAMP v1.x.x

alias mpear="/Applications/MAMP/bin/php5.3/bin/pear"

3) Make a link between php5 and php5.3 folders (Not Needed for MAMP v2.x.x):

Pear gets confused about its version because it installs in both php5.3 and php5 directory

When you upgrade pear it will create a new /Application/MAMP/bin/php5 directory and spread files between php5.3 and php5 folders. Use the code below to make a link between the two file so they act as one. More info about "ln" command. Source: @Marcelo Rodrigo's post

ln -s php5.3 php5

4) Check to make sure pear is working:

mpear -V

5) Now upgrade pear:

mpear channel-update pear.php.net
mpear upgrade pear

6) And check again to see if it upgraded pear correctly

mpear -V


Install PHPUnit

You do not need to install PHPUnit. If mpear -V worked for you, then you are done installing PEAR on MAMP. For my development environment I needed PHPUnit for unit testing, so I figured I would include a tutorial to install PHPUnit now that we have PEAR working. Only do this if you need PHPUnit. If you don't know what it is, you don't need it.

Run the following commands:

1) Install PHPUnit:

NOTE: Below I am using "mpear" which is actually an alias I setup in step 2 above. You could simply use "/Applications/MAMP/bin/php5.3/bin/pear" in its place.

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

Source: http://www.phpunit.de/manual/current/en/installation.html

2) Allow MAMP to use PHPUnit

Link your MAMP's install of phpunit with the default phpunit location. (Doesn't work with Mountain Lion, instead see step 2a)

sudo ln -s /Applications/MAMP/bin/php5/bin/phpunit /usr/local/bin/phpunit

**2a) For Mountain Lion Only - Create a symobolic link between MAMP's php.ini and the php.ini in /etc

sudo ln -s /Applications/MAMP/bin/php/php5.4.4/conf/php.ini /etc/php.ini

If it says files exists, make a backup of /etc/php.ini and delete it.

3) Make sure it works

phpunit --version

For details about installing phpunit check out:


Sources: