Install PHP (compile add) corresponding dynamic expansion module in Centos 7 (Linux) environment (take as an example)

Source: Internet
Author: User
Tags install php install openssl zts


In the CentOS 7 environment to build a good LNMP environment, found that the installation of PHP has a lot of extensions are not installed, their own installation of a lot of problems encountered in the Internet to find information there is no comprehensive solution to the problem, always encountered a variety of errors. Finally, the installation succeeds through various problem handling and various explorations. Now take the expansion installation as an example to illustrate the installation of the PHP extension, the steps are as follows:

First, before installing the extension, it is important to note that PHP has an extension of ". So" in the Linux environment, and PHP with the extension ". dll" in the Windows environment.

Now let's talk about the installation extension steps:

1. First determine the installed PHP version of Linux, because different PHP version for the addition of dynamic modules have compatibility issues (possible path, configuration?). Other? ), often error can not be installed, the additional module must be the same version.

There are several ways to view the PHP version:

① run php-v (but in my 64-bit Linux test it didn't work, cause you know!) )

② in the installed PHP path to find php-config and to view, you can VI or CAT (keyword: version= "XXXXXXX" for the PHP version number)

Vim Php-config


Cat Php-config

In the CentOS 7 environment you can use: PHP--version command to view PHP version

2, to (corresponding PHP version download) address download PHP corresponding installation package, or can be downloaded through the Linux command (refer to my previous article: Build a LNMP environment in the CentOS 7 system installation of PHP) ; If the installation package exists before installation, you do not have to download it;

3, if the local download will be through the FTP tool to upload the PHP source package to your Linux environment, upload successfully after the command to extract:

Unzip the command as follows:

TAR-JXVF php-5.6.7.tar.bz2 (source code tar package)

4, next to the module installation time, into just unpacked PHP source package folder, the execution of configure module append, a command part (my PHP source file package in/root/source below, The source package after decompression is php-5.6.7):

[Email protected] source]# CD./php-5.6.7/ext/openssl #进入源码包的OPENSSL模块文件夹

[[email protected] openssl]#/usr/local/bin/phpize #在这里执行/usr/local/bin/phpize, note that this is an already installed PHP path (hint: If you can't find/usr/lo Cal/bin/phpize, use the command Whereis phpize to find its location, my phpize path is/usr/local/bin/phpize)

An error may be reported after the/usr/local/bin/phpize command is executed: Cannot find config.m4.Make sure that you run '/usr/local/bin/phpize ' in the top

Level source directory of the module.


Check the PHP source package OpenSSL folder for CONFIG0.M4, if any, execute the command:

[Email protected] openssl]# MV CONFIG0.M4 CONFIG.M4

Once execution is complete, execute the/usr/local/bin/phpize command again to get the following result:

Will report one: Cannot find autoconf. Please check your autoconf installation and the $PHP _autoconf environment variable. Then, rerun the this script. the error;


[email protected] ~]# Yum install M4

[email protected] ~]# Yum install autoconf

Next execution:/usr/local/bin/phpize The following results indicate successful execution:

5, next to the compile stage, the compilation process using the following command:

[Email protected] openssl]#/configure--with-openssl--with-php-config=/usr/local/bin/php-config

Note: The/usr/local/bin/php-config here is your PHP installation path, if you do not know it, you can check it through Phpinfo:

No accident, this command will be reported after the completion of a Configure:error:Cannot find OpenSSL ' s <evp.h> error, at the end of the execution completion:


[email protected] ~]# Yum install OpenSSL openssl-devel

[Email protected] ~]# ln-s/usr/lib64/

Execute again:

[Email protected] openssl]#/configure--with-openssl--with-php-config=/usr/local/bin/php-config

The successful results are as follows, and a config.h file is generated at the end:

Proceed to the following command:

[[email protected] openssl]# make# perform compilation

[email protected] openssl]# make test #测试编译的结果

After executing the make Test command, the following results appear, asking if you want to send a report, where I choose N Directly (n is the meaning of No)

Then proceed:

[[email protected] openssl]# make install #进行安装

The following results indicate that the installation was successful:

Remember this path, this path is the ". So" file's storage path, which is used later.


General specification point, the additional so module will be placed in a specified folder, in PHP installed directory under the Extensions folder


At this point, the append compilation of the so dynamic module has all been completed.

6, Next is the configuration, let PHP support loading these additional dynamic modules, Vim editor under the PHP configuration file php.ini

Open PHP configuration file using vim php.ini

After entering the editor, you can see all the relevant configuration of PHP, find extension_dir this configuration option;

VI can be directly after the '/extension_dir ' search, found after this may be:

Extension_dir= "./"

Modify it to:

Extension_dir= "/usr/local/lib/php/extensions/no-debug-non-zts-20131226/"

Note: The/usr/local/lib/php/extensions/no-debug-non-zts-20131226/here is the path that was returned when the make install was executed successfully.

That is where so files are located.

Add to: (so module file name)

Final execution:

": wq!"

Command Save exit

Next, restart the Nginx and PHP services

[Email protected] ~]# Nginx-s Reload

[Email protected] ~]# servive php-fpm restart

The installation of the OpenSSL extension module is complete! If you encounter any problems during the installation process, you can communicate with me in time!

To this CentOS 7 (Linux) environment to install PHP (compile add) the corresponding dynamic extension module so is done.

(Do not know why, the picture uploaded two can not be displayed, on the third upload, if still can not show that there is no way, it can only do so!) )

Install PHP (compile add) corresponding dynamic extension module in Centos 7 (Linux) environment (take for example)

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.