PHP extension in centos

Source: Internet
Author: User
Tags mcrypt phpinfo zts

First, enable the mcrypt software to run, then install the PHP extension module and configure it in PHP. ini.

The mcrypt software depends on the libmcrypt and mhash libraries, so the installation configuration sequence is from right to left.

I download and install mcrypt

1. first go to the to download the libmcrypt, mhash, mcrypt installation package, below is the link I found

Libmcrypt(libmcrypt-2.5.8.tar.gz): Http:// Group_id = 87941 & package_id = 91774 & release_id = 487459

Mcrypt(mcrypt-2.6.8.tar.gz ):

Http:// Group_id = 87941 & package_id = 91948 & release_id = 642101

Mhash(mhash-0.9.9.tar.gz): Http:// Group_id = 4286 & package_id = 4300 & release_id = 645636

2. Install libmcrypt first

# Tar-zxvf libmcrypt-2.5.8.tar.gz

# Cd libmcrypt-2.5.8


# Make

# Make install

Note: libmbench is installed in/usr/local/lib by default.

3. Install mhash

# Tar-zxvf mhash-

# Cd mhash-


# Make

# Make install

4. Install mcrypt

# Tar-zxvf mcrypt-2.6.8.tar.gz

# Cd mcrypt-2.6.8

# LD_LIBRARY_PATH =/usr/local/lib./configure

# Make

# Make install

Note: When mcrypt is configured, The libmcrypt Link Library cannot be found, resulting in compilation failure because the libmcrypt Link Library is in the/usr/local/lib/folder. Because LD_LIBRARY_PATH =/usr/local/lib must be added when mcrypt is configured to import the key Library

Ii. Install the PHP extension module

Then we need to add the mcrypt module for PHP.

1. Static Compilation

Add the phpinfo () function to any PHP file to obtain the current PHP configuration.
Add the configuration to be added after these configurations: '-with-mcrypt =/usr/local/include'
Go to the PHP source code directory and execute the complete configure command.

After the configuration is complete, make and install the source code package.

Make clean (required)
Make install

2. Dynamic Loading [recommended]
A common problem with using PHP is: I forgot to add an extension when compiling PHP. I want to add an extension later. But I didn't want to delete the Directory and reinstall it because I installed something like pear after installing PHP, you can use phpize. The method is:

You must have a PHP compressed package that is exactly the same as the existing PHP package.. I use php-5.2.6.tar.gz. Expand and enter the EXT/mcrypt directory (which is the PHP extension of mcrypt), and then run/usr/local/PHP/bin/phpize. Phpize is a tool installed during PHP installation. If your machine does not have the phpize tool installed, you may still need to make and make install PHP, just to get phpize.

After execution, you will find that some configure files are added to the current directory. If no error is reported, run as prompted.

./Configure-With-PHP-Config =/usr/local/PHP/bin/PHP-config

Make sure that/usr/local/PHP/bin/PHP-config exists.


Make install

After make install SystemThe directory where the mcrypt. So file is located is displayed. According to PhP. in the directory indicated by the extension_dir in ini, copy it (or change the path after = to the path prompted by the make install result, for example: /usr/local/services/php-5.3.5/lib/PHP/extensions/no-debug-non-zts-20090626 /). Modify PHP. ini and add extension = mcrypt. So

Restart the apache service Chakan phpinfo.

When I installed magento, I encountered the extension required by the system.

1. mcrypt
2. pdo_mysql
3. Curl
In fact, most extensions are available in the PHP source code installation package (in ext ).
To add an extension, follow these steps:
1. Enter the extension EXT/.../you want to add in the installation package folder. For example, to add the mcrypt extension, enter EXT/mcrypt. Example: [root @ localhost ~] # D/usr/local/src/php-5-2-13/mcrypt/
2. Call phpize. example in the compiled PHP file: [root @ localhost mcrypt] #/usr/local/PHP/bin/phpize
3. Then, configure. Example: [root @ localhost mcrypt] #./configure -- With-PHP-Config =/usr/local/PHP/bin/PHP-config
4. Make and make install
5. Modify PHP. ini
Add extension =/usr/local/PHP/lib/PHP/extensions/no-debug-non-zts-20060613/Extension
Example: Extension =/usr/local/PHP/lib/PHP/extensions/no-debug-non-zts-20060613/mcrypt. So

6. Restart Apache (Apache/bin/apachectl-K restart)


Note: configuration parameters for pdo_mysql extension Installation
./Configure-with-PHP-Config =/usr/local/PhP5/bin/PHP-config-with-PDO-mysql =/usr/local/MySQL

There is another method

This compilation only compiles the PHP extension library separately, and then adds the compiled PHP extension Library to the currently running PHP, therefore, it has no impact on the currently running PHP.

If the original compiled PHP Directory is under the/usr/local/PhP4 directory; Apache under the/usr/local/apache2 directory; PHP source code under the/home/php-4.4.7 directory. If the actual directory is different from the assumed directory, make adjustments in the following command.

1. Find the source code directory of the currently running PHP version, such as the php-4.4.7. Enter the curl extension library directory.
$ CD/home/php-4.4.7/EXT/curl

2. Call the phpize program to generate the compilation configuration file.

3. Compile the extension library and execute the following configure and make commands respectively.
$./Configure-with-PHP-Config =/usr/local/PhP4/bin/PHP-config
# After configure passes this step, run the make command. If configure fails, find the cause of the error.
$ Make
# After make is successfully executed, the generated extension library file is in the modules subdirectory of the current directory,
For example,/home/php-4.4.7/EXT/curl/modules/curl. So

4. Configure the php. ini file
# Copy the compiled extension library file to The apache2 modules directory.
$ CP/home/php-4.4.7/EXT/curl/modules/curl. So/usr/local/apache2/modules /.
# You can view the phpinfo information to determine the location of the php. ini file and edit it.
# Locate the location of the extension directory in the PHP. ini file and set the extension path to The apache2 modules directory.
Extension_dir = "/usr/local/apache2/modules /"
# Add the extension library location in PHP. ini and set the extension library to be added.
Extension = curl. So
# If you want to add other extension libraries in the future, you only need to compile the PHP extension library and copy it to The apache2 modules directory,
# Add a line at this location to add the name of the compiled extension library file.

5. Restart Apache and view the phpinfo information. The added curl extension library is displayed.

Related Article

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