Search code examples
phpterminalmampphpquery

How do I use terminal to install plugins and libraries for PHP (MAMP)?


Can you walk me through the installation of a library for php, specifically what each terminal command does?

I have been learning web development for 6 months and it is time I need the console / terminal. I can't find any beginner walkthrough of using the terminal to add libraries and plugins to PHP. There are a lot of tutorials for specific steps or errors, but none start to finish.

If you want specifics to make your example concrete, here is what I am trying to install:

The library I am installing: http://code.google.com/p/phpquery/

My directory for PHP on MAMP: /Applications/MAMP/bin/php/php5.3.6/bin

Update: I figured out my specific issue, but I don't think I really understand what I did, so I can't repeat it by myself in any other situation. This thread can help a lot of new terminal users including myself. The type of response I am looking for would go like this:

  1. Open your terminal. (This is an alternative way to navigate and execute commands on files on your computer).

  2. Find out where MAMP is installed however you like. Then go to your terminal, and type in cd followed by the path. cd stands for current directory and tells your terminal where it should execute its commands. The command you use will be very similar to this cd /Applications/MAMP. This will make your current directory MAMP.

  3. You are adding a library to PHP. So you need to go to the PHP folder in MAMP… (Please help us from this part!)


Solution

  • I just checked and it is available in pear channels.

    # this is from their site
    pear channel-discover phpquery-pear.appspot.com  
    pear install phpquery/phpQuery
    

    Of course, for Mac using MAMP, you would use commands like this:

    /Applications/MAMP/bin/php5/bin/pear install [package]
    

    So for PHPQuery, try this:

    /Applications/MAMP/bin/php5/bin/pear channel-discover phpquery-pear.appspot.com
    /Applications/MAMP/bin/php5/bin/pear install phpquery/phpQuery
    

    Same method should apply to pecl extensions as well.


    Update 1: I personally just installed it on mine to test, here were my results:

    $ /Applications/MAMP/bin/php5/bin/pear channel-discover phpquery-pear.appspot.com
    Adding Channel "phpquery-pear.appspot.com" succeeded
    Discovery of channel "phpquery-pear.appspot.com" succeeded
    $ /Applications/MAMP/bin/php5/bin/pear install phpquery/phpQuery
    downloading phpQuery-0.9.5.386-pear.tgz ...
    Starting to download phpQuery-0.9.5.386-pear.tgz (100,990 bytes)
    ......................done: 100,990 bytes
    install ok: channel://phpquery-pear.appspot.com/phpQuery-0.9.5.386
    

    This should work with any PEAR or PECL extension. Check out this page for a list of PEAR packages.


    Update 2: Make sure /Applications/MAMP/bin/php5/lib/php is in your include path! That is where phpQuery.php will be located once you've downloaded the PEAR packages properly with MAMP.


    Update 3: Per ngChris’s comment, he mentioned that these packages are no longer maintained and that you should use this instead:

    $ /Applications/MAMP/bin/php5/bin/pear channel-discover pear.querypath.org 
    $ /Applications/MAMP/bin/php5/bin/pear install querypath/QueryPath