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 “”.

  • 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.


Add Yours →

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.

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.

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

I get the following errors

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

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?

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:

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

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

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.


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

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:

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

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

Leave a Reply