22

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

2

3 Answers 3

51

@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:

1
  • 1
    This was very helpful, though I found that I had to also run '/Applications/MAMP/bin/php/php5.4.10/bin/pear channel-discover pear.symfony.com' in order for things to complete successfully. Other documentation I've seen only had me adding the pear.phpunit.de channel and the pear.symfony-project.com, while adding pear.symfony.com made this completeable. Thanks
    – DaOgre
    Jul 3, 2013 at 0:33
7

If you just want phpunit to work, use the following commands on a fresh copy of MAMP 1.9.5:

cd /Applications/MAMP/bin
ln -s php5.3 php5
php5/bin/pear channel-discover pear.phpunit.de
php5/bin/pear channel-discover components.ez.no
php5/bin/pear channel-discover pear.symfony-project.com
php5/bin/pear channel-update pear.php.net
php5/bin/pear upgrade pear
php5/bin/pear install phpunit/PHPUnit
ln -s /Applications/MAMP/bin/php5/bin/phpunit /usr/local/bin/phpunit
phpunit --version

Done.

The above code fixes the following issues:

Bug 1: pear gets confused about its version because it installs in both php5.3 and php5 directory

Pear updates upgrades and installs from /Applications/MAMP/bin/php5.3/pear, but it will create a new /Application/MAMP/bin/php5 directory and spread files between the php5.3 direct and the new php5 directory and get very confused about what version it is.

Fix: ln -s php5.3 php5

I think that if you are using PHP 5.2 then using ln -s php5.2 php5 should work equally well but I haven't tested this

Issue 2: pear is out of date

this is understandable of the MAMP team, the problem really was that it was difficult to do a upgrade because of Bug 1

Source: http://forum.mamp.info/viewtopic.php?f=6&t=11102

6

I recently found the following link correctly setup my MAMP 2.1.1 running:

PEAR Version: 1.9.4
PHP Version: 5.4.4
Zend Engine Version: 2.4.0

Try:

sudo /Applications/MAMP/bin/php/php5.4.4/bin/pear config-set auto_discover 1
sudo /Applications/MAMP/bin/php/php5.4.4/bin/pear install pear.phpunit.de/PHPUnit

To make it available on the command line everywhere you need to create a soft-line to phpunit in your local bin.

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

Now try:

 phpunit --version
  1. Confirm it works try it from here: /Applications/MAMP/bin/php/php5.4.4/bin/
  2. Confirm the symlink worked. Try it somewhere else like ~/ or /.

If they both worked you are ready to code.

SOURCE/CREDIT: Enej Bajgoric Web Developer, CTLT UBC Vancouver Canada at http://blogs.ubc.ca/enej/2012/10/01/installing-phpunit-on-mamps/

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.