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.
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.
相关文章推荐
- How to install PHP pthreads extension on Ubuntu?
- 【转】How to build and install PHP 5.6.9 from source on Ubuntu 14.04 VPS
- How To Install Linux, Apache, MySQL, PHP (LAMP) stack on Ubuntu 16.04
- How to install php evn on ubuntu
- How to install and configure Apache, PHP, MySql and phpMyadmin on ubuntu
- How to install and configure Apache and PHP on ubuntu
- How To Install Linux, nginx, MySQL, PHP (LEMP) stack on Ubuntu 12.04
- How To Install Linux, Apache, MySQL, PHP (LAMP) stack on Ubuntu 14.04
- How to Install PHP intl extension on OS X
- How to install/setup latest version of PHP 5.5 on Ubuntu 12.04 LTS (Precise Pangolin)
- How To Install LAMP (Linux, Apache, MySQL, PHP) On Ubuntu 11.04/11.10/12.04
- How to Install AMQP PHP Extension and RabbitMQ Client on Linux
- How to install and configure Apache, PHP, MySql and phpMyadmin on ubuntu
- How to install GSL on linux (ubuntu)
- how-to-install-vnc-server-on-ubuntu-14.04
- How to install jdk on Ubuntu
- digitalocean --- How To Install Apache Tomcat 8 on Ubuntu 16.04
- How to install and use GCC g++ v4.7 and C++11 on Ubuntu 12.04
- How to install subversion 1.7 (svn1.7) on ubuntu14.04 LTS [Tested By Carson Zang, passed!]
- How to Install Apache Tomcat 8 (on Windows, Mac OS X, Ubuntu) and Get Started with Java Servlet Prog