Friday, June 21, 2013

How to install a PHP PECL extension/module on Web Server

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 on server using the PECL_HTTP extension as an example and assumes that you already have Apache 2 and PHP 5 installed:

  1. 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 -y install php-pear
 
    2.  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 -y install php5-dev


  3.  The PECL_HTTP extension requires an additional dependency package to be installed.
You can probably skip this for other extensions:
       sudo apt-get -y install libcurl3-openssl-dev

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

5.  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 Server 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”. 
 
 
6.  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 
 


























No comments: