Friday, September 23, 2011

Installing PHP's Pear on MacOS Lion

This blog post will cover the installation process of PHP's pear on MacOS Lion.

Googling revealed several blog posts for Leopard.  The first of which I encountered was, How To Install PEAR in Mac OS X Leopard.  The first instruction is not consistent with the version of PHP distributed with Lion, which prompted this blog article.  I received the following error:
Sorry!  Your PHP version is too new (5.3.6) for this go-pear.
Instead use http://pear.php.net/go-pear.phar for a more stable and current
version of go-pear, more suited to your PHP version.
If you are using Lion, follow these instructions for completing the installation process for pear.

The first step is downloading the pear PHAR.  Make sure that you execute this command in a directory where you have write permissions.  I chose my home directory.
curl http://pear.php.net/go-pear.phar > go-pear.phar
Next, run go-pear to complete the installation process of the library.
sudo php -q go-pear.phar
When prompted with the installation locations, change the "Installation base" setting to /usr/local/pear.  Press enter, and watch the installation complete.

As documented in the installation instructions in the posting, How To Install PEAR in Mac OS X Leopard, you will need to create the php.ini.  (I am documenting the steps here for completeness.)

Copy php.ini.default to php.ini.
sudo cp /etc/php.ini.default /etc/php.ini
Next, edit the php.ini file.
sudo vi /etc/php.ini 
Lastly, update the php.ini configuration to include following line to reference pear libraries.
include_path = ".:/usr/local/pear/share/pear"
Restart your Apache server or run your PHP script.  Everything should work as expected.

11 comments:

  1. hi, I followed your steps, when I did 'sudo php -q go-pear.php', I still got the message
    'Sorry! Your PHP version is too new (5.3.6) for this go-pear.
    Instead use http://pear.php.net/go-pear.phar for a more stable and current
    version of go-pear, more suited to your PHP version.'

    How can i make sure that i execute this command in a directory where i have write permissions?

    ReplyDelete
  2. I updated the curl command to capture the go-pear.phar library to a file. Not sure if that was causing you issues.

    Does that happen after downloading the latest version of go-pear.phar? I just tried it myself again without any errors. My version of PHP is 5.3.6. Here are the full details of running 'php -v'

    PHP 5.3.6 with Suhosin-Patch (cli) (built: Sep 8 2011 19:34:00)
    Copyright (c) 1997-2011 The PHP Group
    Zend Engine v2.3.0, Copyright (c) 1998-2011 Zend Technologies

    ReplyDelete
    Replies
    1. My php version is the same as yours. I tried again, but it still comes to the problem I mentioned.

      How to updated the curl command to capture the go-pear.phar library to a file ?

      Delete
    2. how can I show you my shortcut picture ?

      Delete
  3. The following is the process:

    Yang-WenmatoMacBook-Pro:~ Young$ curl http://pear.php.net/go-pear.phar > go-pear.phar
    % Total % Received % Xferd Average Speed Time Time Time Current
    Dload Upload Total Spent Left Speed
    100 3594k 100 3594k 0 0 27867 0 0:02:12 0:02:12 --:--:-- 33590
    Yang-WenmatoMacBook-Pro:~ Young$ sudo php -q go-pear.php
    Password:
    PHP Deprecated: Assigning the return value of new by reference is deprecated in /Users/Young/go-pear.php on line 733
    Sorry! Your PHP version is too new (5.3.6) for this go-pear.
    Instead use http://pear.php.net/go-pear.phar for a more stable and current
    version of go-pear, more suited to your PHP version.

    Thank you for your coopertion and sorry for the inconvenience!


    and Thank you for helping me!

    ReplyDelete
    Replies
    1. Everything you have done is identical to what I have done. I wonder if you have a different reference to php in your path. When I do "which php" it returns the path "/usr/bin/php". I would verify that it is the same when you run "sudo which php". Your root account may have a different path setting which could maybe possibly cause an issue. I am really kind of just grasping at straws.

      Delete
    2. when i type 'which php' it returns the same path "/usr/bin/php".

      do you think i need to install an old version php to finish it ?

      Delete
    3. There is one other discrepancy I see in my post. Make sure you are executing the following: 'sudo php -q go-pear.phar'. You might have a .php file in that same location. That could be causing the problems you are seeing. That may be an older version that is causing the issue.

      Delete
  4. I had trouble to run 'sudo pear install "package"' (sudo: pear: command not found)
    that was fixed when I added export PATH=/usr/local/pear/bin:$PATH in my ~/.bash_profile

    ReplyDelete
  5. thanks dajjen I had the same problem!

    ReplyDelete
  6. hi...Im student from Informatics engineering nice article,
    thanks for sharing :)

    ReplyDelete