How to compile the install PHP extension ____php

Source: Internet
Author: User
Tags bz2 create index fpm install php intl php print php source code git clone

This article refers to

As soon as we started installing PHP, we didn't know what extensions were needed, so we had to wait until we actually used them to find a way to install them.

The easiest way to install PHP extensions is to

sudo apt-get install php5-xxx

But sometimes it is not what we want, the source does not have the expansion we need, this time we need to download the source code to build their own installation.

In this article I will describe how to compile and install PHP extensions under the local Linux platform.

Now create index.php print basic configuration information in the site root directory to verify that we have successfully installed. Configuring the compilation Environment

We need to install some libraries that must be compiled and Php-dev version of Ubuntu

sudo apt-get install php5-dev php5-mysql gcc Libpcre3-dev
Fedora
sudo yum install php-devel php-mysqlnd gcc Libtool
RHEL
sudo yum install php-devel php-mysql gcc Libtool
Suse
Yast2-i php5-pear php5-devel php5-mysql gcc
Install extension

PHP has two extensions to install: one that is native to PHP but is not installed by default, and the other is an extension of third-party development.

The following describes the installation methods for both extensions:

Before installing, we need a copy of the same version of PHP as the current machine.

CD Code
wget http://cn2.php.net/distributions/php-5.5.9.tar.bz2
tar xvjf php-5.5.9.tar.bz2
CD php-5.5.9

Go here to download the corresponding source package.

All PHP native extensions are visible below the/ext directory. Install native Extensions

Take Php-intl as an example, this is an extension of the internationalization of PHP.

In order to install this extension we need to first install the ICU library

sudo apt-get install icu-devtools icu-doc libicu-dev libicu52

After the ICU installation is successful, enter the/EXT/INTL directory:

CD Intl
phpize
./configure--enable-intl
make
sudo make install

The following explains each of the above commands: Phpize: is used to extend the PHP extension module, through the phpize can build PHP plug-in module./configure--ENABLE-INTL: Configure the compilation environment, The equivalent of telling the compiler to compile the PHP source code when adding intl this extension. Make: The source code will be compiled into intl.so make install: The intl.so will be moved to the currently installed PHP extension directory.

The next thing we want to do is enable this extension in php.ini, which will be shown at the end of the example. installing third party extensions

Take this extension as an example, this extension mainly realizes the function of the PHP to recognize the barcode.

Install the necessary dependencies first

sudo apt-get install Pkg-config
git clone https://github.com/mongodb/mongo-php-driver
cd mongo-php-driver
phpize
./configure
Make
sudo make install

A file will be generated and copied to the extended directory of PHP. Enable extension

There are many ways to enable extensions in php.ini: adding extension=mongo.so directly to the php.ini file is the simplest and most straightforward method. You can also build an INI file separately, and then include these files in the php.ini.

Here's a second way to do this:

CD '/etc/php5/mods-available '

This directory can be placed in the new INI file, and then execute

sudo touch Mongo.ini
echo "extension=mongo.so" | sudo tee-a mongo.ini
sudo touch intl.ini
echo "Extension=in Tl.so "| sudo tee-a Intl.ini

The above command will create the INI file and write as appropriate configuration information.

Then execute the following command to enable the extension (you need to install the Php5enmod tool):

sudo php5enmod MONGO
sudo php5enmod Intl

If the Php5enmod tool is not installed, you will need to manually configure:

Ln-s/etc/php5/mods-available/mongo.ini/etc/php5/cli/conf.d/mongo.ini
ln-s/etc/php5/mods-available/intl.ini /etc/php5/cli/conf.d/intl.ini
ln-s/etc/php5/mods-available/mongo.ini/etc/php5/fpm/conf.d/mongo.ini
LN- S/etc/php5/mods-available/intl.ini/etc/php5/fpm/conf.d/intl.ini

Finally, the restart operation is done:

sudo Service nginx Restart sudo service php5-fpm restart 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.