Installing PEAR 1.9.2 with MAMP and PHP 5.3 on Mac OSX 10.6

Installing Pear 1.9.2 with MAMP

Installing PEAR 1.9.2 with MAMP 1.9.1 and PHP 5.3.2 on Mac OSX 10.6

This was a lot harder than I think it should have been. I tried following the instructions on the following sites but despite saying that there was “nothing to upgrade” it was still saying version 1.9.0.

http://serverfault.com/questions/184741/upgrading-pear-from-1-9-0-to-1-9-1-fails
http://startrekguide.com/community/viewtopic.php?f=50&t=14728
http://jamsyoung.com/2011/02/11/upgrading-pear-on-mamp/

Using the “go-pear.php” method resulted in the following error:

"Sorry! Your PHP version is too new (5.3.2) for this go-pear."

and using the “pear upgrade pear” method resulted in

"Download of "pear/Console_Getopt" succeeded, but it is not a valid package archive".

At one point I also got the amusing error message saying that it couldn’t upgrade to 1.9.1 because pear/Console_Getopt needed version 1.9.1 to install.

Finally (after installing it in the wrong place twice) I found this method which did work:

Installing Pear 1.9.2

1) Open a new terminal session.

2) Edit your .bash_profile:


edit ~/.bash_profile

so that it contains the following (add it under anything you already have).


PATH="/Applications/MAMP/Library/bin:/Applications/MAMP/bin/php5.3/bin:$PATH"

3) Close terminal and re-open it then type

echo $PATH

It should contain the new MAMP paths. If it doesn’t, something went wrong (make sure you’re in your home directory).

4) Check that you’re running the right PHP (i.e. the one included with MAMP, not the one included in OSX) by typing:

which php

It should read:

/Applications/MAMP/bin/php5.3/bin/php

5) If it says

/usr/bin/php

then you need to either create a symlink to the MAMP version or delete it from here and update your path in your .bash_profile (see above — remember to restart terminal to start a new session).

I backed up the original Snow Leopard versions of PHP and Pear and then deleted them by doing the following:

cd /usr/bin
sudo cp php php.bak
sudo cp pear pear.bak
sudo rm php
sudo rm pear

6) Download pear.php.net/go-pear.phar to /Applications/MAMP/bin/php5.3/:

cd /Applications/MAMP/bin/php5.3
curl -O http://pear.php.net/go-pear.phar
php go-pear.phar

7) You’ll be asked to set the directories. You only need to set the first one and the rest will be correctly created. Choose “1″ and then type:

/Applications/MAMP/bin/php5.3

Hit return.

8) It will then ask you if you want to update your php.ini. Type “Y” and hit enter.

Once it’s all installed, you’ll see a message saying that you have to update your $PATH variable. If you haven’t already (see step 1), do this now then restart Terminal.

9) Type pear -V and it should now be 1.9.2.

You can then install all the packages you like. Remember that PHPUnit is now on its own channel and you’ll have to make pear aware of that new channel by running

pear channel-discover pear.phpunit.de

Did You Enjoy This Post?


About Simon

Simon is a professional web designer and developer with over 10 years experience.

31 Responses to Installing PEAR 1.9.2 with MAMP and PHP 5.3 on Mac OSX 10.6

  1. Ramesh Kunhiraman

    Good Post. Very good set of instructions. It worked for me. I wasted lot of effort in trying to set my PEAR to 1.9.2

    Thanks again


  2. Thanks Simon! One of the very few blog posts on this subject that worked for me. You’re right, installing pear and phpunit shouldn’t be this hard, its ridiculous.


  3. FanQuake

    Cheers for the article, ive finally got my Unit Tests running :)


  4. Oh my goodness, I have been searching for this solution for 2 days. Thank you so much!


  5. Julien

    Hey,
    Thanks a lot !
    I done everything you wrote but i have a problem when i’m using “pear -V” it says :
    /Applications/MAMP/bin/php5.3/bin/pear: line 28: /Applications/MAMP/bin/php5/bin/php: No such file or directory
    /Applications/MAMP/bin/php5.3/bin/pear: line 28: exec: /Applications/MAMP/bin/php5/bin/php: cannot execute: No such file or directory

    I done everything good I can’t understand…
    some help please :D


    • Simon

      Hi Julien,

      I think your MAMP install must be either an older version or installed in a different location. If you run

      which php

      That will tell you where your PHP install is located. You then need to use that directory in both the ~/.bash_profile (step 2) and in the PEAR setup directory (step 7).

      Hope that helps.


  6. Julien

    OK ’cause it says “/Applications/MAMP/Library/bin/php”


    • Julien

      I tried to use that path (/Applications/MAMP/Library/bin) in the two step you says and in the step 6 too but now, when I’m writiing pear -V it says : “-bash: pear: command not found”


      • Simon

        Try typing “/Applications/MAMP/Library/bin/pear -V” and see what happens.

        If that doesn’t work, then it means that Pear isn’t installed in the /Applications/MAMP/Library/bin directory. You’ll need to follow the instructions from step 6 (and where it says “/Applications/MAMP/bin/php5.3″, write “/Applications/MAMP/Library/bin”).


        • Julien

          I already done this before !
          It says “-bash: /Applications/MAMP/Library/bin/pear: No such file or directory”…

          I’ll try all the topic with the good repo which php, but i done it..


          • Simon

            From what you said, all you typed previously was “pear -V”. For this to work, it means that Pear has to be installed in one of the system’s default binary folders, or in a user defined binary folder (set as a $PATH variable in your ~/.bash_profile).

            I was asking you to type in the whole path “/Applications/MAMP/Library/bin/pear -V”, which will execute it whether or not it’s in the binary folders or set as a $PATH variable. This was to determine whether Pear existed in that folder at all.

            If it worked, it would have indicated a problem with your $PATH variable. If not, it would indicate that Pear isn’t installed in that folder at all.


          • Julien

            How can I reset the “PATH” var ?
            ‘Cause there is too much link in it…


  7. Julien

    Here is what I have in result…
    It doesn’t work at all, I really do not understand…

    Somebody knows ?


  8. Julien

    Here is what I have in result…
    It doesn’t work at all, I really do not understand…

    Somebody knows ?

    IMAGE


    • Simon

      It’s installed in one bin subfolder too many. (i.e. it’s installed in “/Applications/MAMP/Library/bin/bin”).

      Easy fix. Type this:

      edit ~/.bash_profile

      Then add this:

      PATH="/Applications/MAMP/Library/bin:/Applications/MAMP/Library/bin/bin:$PATH"

      Save the file and you should be good to go.


      • Julien

        Done! But pear -V doesn’t work at all -bash: pear: command not found

        And ls /Applications/MAMP/Library/bin/bin
        pear peardev pecl

        And finaly :
        /Applications/MAMP/Library/bin/bin/pear: line 28: exec: /Applications/MAMP/bin/php5/bin/php: cannot execute: No such file or directory


        • Julien

          It works :D
          Thx :D

          Now i want to use pear mail..


          • DAME

            I know this was a long time ago, but do you happen to remember what you did to get this to work. I have the same exact problems you had


  9. Peter Nicholls

    HELP! PhpUnit will not install!


    Failed to download pear/HTTP_Request2 within preferred state "stable", latest release is version 2.0.0RC1, stability "beta", use "channel://pear.php.net/HTTP_Request2-2.0.0RC1" to install
    phpunit/PHPUnit can optionally use PHP extension "dbus"
    pear/XML_RPC2 requires package "pear/HTTP_Request2" (version >= 0.6.0)
    phpunit/PHPUnit requires package "pear/XML_RPC2"
    No valid packages found
    install failed

    That’s what I get. I have done this over and over and 8 hrs later. i am frustrated!


  10. Peter Nicholls

    Please ignore last post by me, have now got past that stage. However I’m unsure it’s gone right, and what the next stage should be?

    phpunit is now in:
    …php5.3>share>pear>PHPUnit…
    is this correct?

    and i am getting this response:
    bash-3.2# phpunit
    bash: phpunit: command not found

    Please can anyone help with the solution here? THank you!


    • I keep getting

      Failed to download pear/HTTP_Request2 within preferred state “stable”, latest release is version 2.0.0RC1, stability “beta”, use “channel://pear.php.net/HTTP_Request2-2.0.0RC1″ to install

      I dont know what to do.. Im trying to install PHPUnit all day today :(
      Please help.


  11. brian

    Thank you, I wanted to PHPUnit for testing a new web app, but wasn’t sure how to jump through the hoops first.


  12. Finally a great post that walks you through ALL of the steps to get pear up and running in MAMP.

    Only hiccup: typing pear -V produced the following 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.

    The fix is to delete pear.conf from /Applications/MAMP/bin/php/php5.3.6/conf

    After deleting the config file everything is working fine.


  13. rob

    THANK GOD FOR THIS POST! Because of MAMP this whole situation had me totally screwed up! THanks bro!


Trackbacks and Pingbacks

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>