您的位置:首页 > 编程语言 > PHP开发

How to install a PHP PECL extension/module on Ubuntu

2011-10-25 18:20 381 查看
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.
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: