How to install a PHP PECL extension/module on Ubuntu

PHP PECL extensions provide additional functionality over the base PHP install. You can browse the PHP PECL extensions available at the PECL repository here. The following steps show how to install a PECL extension/module on Ubuntu using the PECL_HTTP extension as an example and assumes that you already have Apache 2 and PHP 5 installed:

  • First, you will need to install PEAR via apt-get to get the necessary package and distribution system that both PEAR and PECL use. From a shell prompt enter:
    sudo apt-get install php-pear

    You will be prompted to confirm the install. Just press “y” and enter. If all goes well you should see it download and install the php-pear package.

    Note: “sudo” is used to provide the super user privileges necessary for the following command. So in this case the command “apt-get install php-pear” is being executed with super user privileges by preceding it with “sudo”. Unless configured otherwise, you will normally be prompted to enter a password when you use sudo. This is usually the same password that you logged in with.
  • Now you will need to install the php5-dev package to get the necessary PHP5 source files to compile additional modules. Enter the following from a shell prompt:
    sudo apt-get install php5-dev

    If you do not install the php5-dev package and try to install a PECL extension using “pear install”, you will get the following error:

    sh: phpize: not found
    ERROR: `phpize’ failed
  • The PECL_HTTP extension requires an additional dependency package to be installed. You can probably skip this for other extensions:
    sudo apt-get install libcurl3-openssl-dev
  • Now we are finally ready to actually install the extension. From a shell prompt enter following but substitute “pecl_http” with the PECL extension name you are installing:
    sudo pecl install pecl_http

    The installer may ask you about some specific options for the extension you are installing. You can probably just hit enter one or more times to accept all the defaults unless you want to set specific options for your implementation. If all goes well, the module should download, build, and install.

  • Once the install is complete, it will probably ask you to add a “extension=” line to your php.ini file. Open up the php.ini file in your favorite text editor and add the line under the section labeled “Dynamic Extensions”. On Ubuntu the php.ini file seems to be located in the /etc/php5/apache2 folder:
    sudo nano /etc/php5/apache2/php.ini

    In this example, the pecl_http extension install asked me to add “extension=http.so”.

  • Now that the php.ini file has been updated, Apache will need to be restarted so the new extension will be loaded:
    sudo /etc/init.d/apache2 restart

    That should restart Apache on Ubuntu but if that doesn’t work you can try:

    sudo /etc/init.d/httpd restart

If all went well your PECL extension should now be working. You might want to write a PHP test page that will test the basic functionality of the extension to make sure everything is working OK. You can use this later to check that all your required extensions are installed and working when you deploy to a new server. In this example where I installed the PECL_HTTP module, I might write a PHP page that uses the extension’s HttpRequest class to go get a page and return the results.

That’s it. For the next extension install you can skip the steps to install the php-pear and php5-dev packages.

Comments

32 responses to “How to install a PHP PECL extension/module on Ubuntu”

  1. Wasca Avatar
    Wasca

    Thanks for this article is was very handy.

  2. mrojas Avatar
    mrojas

    Thank you very much…I was able to get it configured thanks to your nice howto.

  3. JeSTeR Avatar
    JeSTeR

    I just wanted to point out that having the build-essential package (on Ubuntu at least) is necessary prior to this installation or it will fail when attempting to create a makefile.

  4. moli Avatar
    moli

    thank you.

  5. Andre Avatar
    Andre

    Excellent article, congratulations !! Helped me a lot

  6. Rozza Avatar
    Rozza

    Thanks for the article. Worked perfectly on my Debian 5 install.

  7. thedp Avatar
    thedp

    All I got out of “pecl install PACKAGE” was done downloading.
    How can I verify the extension is there without actually using the php functions?

    Thank you.

  8. mfoster Avatar

    thedp, Try “pecl list”. That should list all the packages you have installed. BTW, “pecl help” will give a list of pecl commands.

  9. Shaun Avatar
    Shaun

    I get the following errors

    sudo pecl install pecl_http
    [sudo] password for naturofix:
    No releases available for package “pecl.php.net/pecl_http”
    install failed

  10. […] sudo /etc/init.d/apache2 restart Referencias Documentación oficial de la extensión Articulo en el que me he basado para escribir esta entrada. […]

  11. Hugo Leon Avatar

    Great article, I spent almost 2 days trying to fix this.

    Thanks a lot!

  12. g Avatar
    g

    I found out a nice case;
    1) PC has already php 5.2.x and along with its Apache2

    now question is how to make this php-pecl module installed without removing its current php?

  13. Diego Avatar

    thank you, it helped me a lot!

  14. anne Avatar
    anne

    My hero! Thanks a lot 😉

  15. Andy Fraley Avatar

    Great article, thanks! Instead of adding “extension=” to php.ini, though, the Ubuntu way would be to create a new ini file in /etc/php5/apache2/conf.d/ and add the “extension=” to that.

    So /etc/php5/apache2/conf.d/http.ini would contain: extension=http.so

  16. Rajesh Avatar
    Rajesh

    Thanks dear.

    Very nice and helpfull article

  17. Vasiliy Baukin Avatar
    Vasiliy Baukin

    Very useful, worked like charm, thanks!

  18. GSW Avatar
    GSW

    behind proxy :
    pear config-set http_proxy http://myproxy.example.com:8080/

  19. Pierrick Avatar
    Pierrick

    Very helpful, many thanks.

  20. danny Avatar
    danny

    on virtual servers it seems I can’t even get any pecl installs to download and install. all other things run fine though.

  21. NV Avatar
    NV

    Awesome. Thanks for publishing this. Such a clunky installation. Would have taken way longer to figure out with out this. Thank you!

  22. Mel Lester Jr. Avatar

    Thanks for de-mystifying pecl installation. The many ways to do things can be quite confusing for tasks I don’t do regularly. Your process worked great and was very well explained.

    By the way, this was done on a Ubuntu 12.04LTS Virtualbox guest with an Apple Mac-Mini host running OSX 10.8. I need to be able to read xBase (FoxPlus) data files from a legacy application in order to sync with MySQL.

    -meljr

  23. chad Avatar

    Thanks for the installation info. It’s almost pecl wants to make it difficult to install extensions.

    Quick note, anybody using Ubuntu follow these comments as well. Not exactly sure what they do, but it worked for me! (as well as for pecl stats.so)

    Great article, thanks! Instead of adding “extension=” to php.ini, though, the Ubuntu way would be to create a new ini file in /etc/php5/apache2/conf.d/ and add the “extension=” to that.

    So /etc/php5/apache2/conf.d/http.ini would contain: extension=http.so

  24. Glenn J. Schworak Avatar

    THANK YOU SO MUCH!

    I did end up having to add one command before php_html would install but all the rest was fantastic.

    sudo apt-get install libpcre3-dev

  25. Mian Khurram Ijaz Avatar

    Thanks a lot , it really helped me installing and making twitter oAuth work

  26. scucimaro Avatar
    scucimaro

    Hi I tryed the procedure with Debian Wheezy on Raspberry pi. It works fine untill the end. phpinfo() gives me the new extension installed.
    propro
    raphf
    but nothing about pecl that is what I need to read mp3s tag
    I add in …/apache2/php.ini
    extension=raphf.so
    extension=propro.so
    extension=http.so
    in Dynamic extension section.
    It doesn’t work!
    When I try a simple script as

    it socks…
    What did I do wrong? Any suggestion?

  27. scucimaro Avatar
    scucimaro

    sorry you strip php code…:-)
    the code is
    $genres = id3_get_genre_list();
    print_r($genres);

  28. Aravind Avatar
    Aravind

    Helpful! Thanks

  29. Erik Figueiredo Avatar
    Erik Figueiredo

    Thanks a lot! It worked fine!

Leave a Reply