"Go" how to compile and install PHP extensions

Source: Internet
Author: User
Tags intl php source code

This article references

When we started to install PHP, we didn't know what extensions were needed, so we only had to wait until we actually used them to install them.

The simplest 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'll show you how to compile and install PHP extensions on a local Linux platform.

Now create the index.php print basic configuration information under the site root to verify that we have successfully installed.

Configuring the compilation Environment

We need to install some libraries that must be compiled, as well as php-dev versions

Ubuntu
sudo apt-get install php5-dev php5-mysql gcc libpcre3-dev
Fedora
install php-devel php-mysqlnd gcc libtool
RHEL
install php-devel php-mysql gcc libtool
Suse
yast2 -i php5-pear php5-devel php5-mysql gcc
Install extensions

PHP has two extensions that are available for installation: one that is native to PHP but not installed by default, and another that is a third-party development extension.

Here are two ways to install the extensions:

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

cd codewget http://cn2.php.net/distributions/php-5.5.9.tar.bz2tar xvjf php-5.5.9.tar.bz2cd php-5.5.9

Go here to download the appropriate source package.

/extyou can see all the PHP native extensions below the directory.

Installing native extensions

PHP-intlFor example, this is an extension of PHP internationalization.

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

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

After the ICU installation is successful, enter the /ext/intl directory:

--enable-intlmakesudo make install

Here's an explanation of each of the commands above:

    • 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, equivalent to tell the compiler to compile the PHP source code when adding intl this extension.
    • Make: Will compile the source code into intl.so
    • Make install: will move the intl.so to the currently installed PHP extension directory.

The next thing we want to do is to php.ini enable this extension in, and this step will show an example at the end.

Install third-party extensions

This extension, for example, mainly implements the PHP barcode recognition function.

Install the necessary dependencies first

sudo apt-get install pkg-config
git clone https://github.com/mongodb/mongo-php-drivercd mongo-php-driverphpize./configuremakesudo make install

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

Enable extension

There are a number of ways to enable extensions in php.ini:

    1. extension=mongo.soThis is the simplest and most straightforward way to add directly to the php.ini file.
    2. You can also build an INI file separately, and then include the files in the php.ini.

The second method is described below:

cd `/etc/php5/mods-available`

This directory can be used to put the new INI file, and then execute

sudo touch mongo.iniecho "extension=mongo.so" | sudo tee -a mongo.inisudo touch intl.iniecho "extension=intl.so" | sudo tee -a intl.ini

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

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

sudo php5enmod mongosudo php5enmod intl

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

-s /etc/php5/mods-available/mongo.ini /etc/php5/cli/conf.d/mongo.iniln -s /etc/php5/mods-available/intl.ini /etc/php5/cli/conf.d/intl.iniln -s /etc/php5/mods-available/mongo.ini /etc/php5/fpm/conf.d/mongo.iniln -s /etc/php5/mods-available/intl.ini /etc/php5/fpm/conf.d/intl.ini

Finally, a reboot operation is performed:

Select AllCopyput it in your notes .
sudo service nginx restartsudo service php5-fpm restart

"Go" how to compile and install PHP extensions

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.