Three PHP Extension Installation Methods under CentOS

Keywords: PHP MongoDB yum Nginx

Under CentOS, PHP has many ways to install and expand, including package-managed yum installation, pecl installation, and source code compilation installation.
Package-managed installation and uninstallation is particularly convenient, while source-code-compiled installation is convenient for parameter tuning.
Generally build the management installation of the recommendation package of the local development environment, saving time. On-line deployment environments recommend compilation and installation for easy tuning.
This article takes MongoDB Extension `Installation as an example.

tool

  • PHP version: 7.0.17

  • Nginx : 1.10.2

  • VMware version number: 12.0.0

  • CentOS version: 7.0

I. yum Installation

yum installation can automatically install extended. so dynamic library and configure php.ini

Note:

  • Make sure you have corresponding extensions in your yum source

  • Restart server Nginx or Apache after installation

  • The browser accesses the index.php file and outputs phpinfo information. If there is MongoDB information, the installation is successful.

[root@localhost ~]yum search mongodb|grep php        # Search for MongoDB extensions in yum sources
[root@localhost ~]yum -y install php70w-pecl-mongo   # Install the MongoDB extension for the corresponding version of PHP
[root@localhost ~]systemctl restart nginx            # Restart Nginx


II. pecl installation

Official documents: http://php.net/manual/zh/mong...

[root@localhost ~]# pecl install mongodb
-bash: pecl: No command found

Direct input of pecl install mongodb will cause an error, indicating that pecl is not installed. Install pecl

[root@localhost ~]# yum -y install php70w-pear
[root@localhost ~]# pecl install mongodb
configure: error: Cannot find OpenSSL's <evp.h>
ERROR: `/var/tmp/mongodb/configure --with-php-config=/usr/bin/php-config' failed

At this point, there will be an error. We need to install openssl and continue to execute the last unsuccessful command after the installation is completed.

[root@localhost ~]# yum -y install openssl openssl-devel
[root@localhost ~]# pecl install mongodb
[root@localhost ~]# systemctl restart nginx             # Restart Nginx

After installation, load the MongoDB extension in the PHP configuration file php.ini

  • Restart server Nginx or Apache after installation

  • The browser accesses the index.php file and outputs phpinfo information. If there is MongoDB information, the installation is successful.

3. Source Code Compiling and Installation

Source Code Compiler Package Download List: https://pecl.php.net/packages...
Mongodb package download address: https://pecl.php.net/package/...

[root@localhost ~]# wget http://pecl.php.net/get/mongodb-1.2.8.tgz# Download source packages
[root@localhost ~]# tar zxf mongodb-1.2.8.tgz  #decompression
[root@localhost ~]# cd mongodb-1.2.8
# Maybe / usr/local/php/bin/phpize found its own phpize file, the same as php-config
[root@localhost mongodb-1.2.8]# /usr/bin/phpize    
Configuring for:
PHP Api Version:         20151012
Zend Module Api No:      20151012
Zend Extension Api No:   320151012
[root@localhost mongodb-1.2.8]# ./configure --with-php-config=/usr/bin/php-config
configure: error: Cannot find OpenSSL's <evp.h>

At this point, it's a familiar taste and a familiar feeling. We need to install openssl and continue to execute the last unsuccessful command after the installation is completed.

[root@localhost mongodb-1.2.8]# yum -y install openssl openssl-devel
[root@localhost mongodb-1.2.8]# ./configure --with-php-config=/usr/bin/php-config
# Make sure you install GCC + + without installing yum-y install GCC + +
[root@localhost mongodb-1.2.8]# make && make install # Compile

Description: php-config is a simple command-line script for getting information about the installed PHP configuration.

When compiling extensions, if you install multiple PHP versions, you can use the -- with-php-config option when configuring to specify which version to compile with, which specifies the path of the corresponding php-config script.

Compiled successfully as follows

At this point, load the MongoDB extension in the PHP configuration file php.ini

  • Restart server Nginx or Apache

  • The browser accesses the index.php file and outputs phpinfo information. If there is MongoDB information, the installation is successful.

  • [root@localhost mongodb-1.2.8]# systemctl restart nginx   # Restart Nginx

    Summary:

    • The difference between pecl installation and source code compilation installation is that the latter is more convenient for parameter tuning.

    • In choosing mongo extensions, the authorities provided two types: mongo and mongodb.

    The first is: https://pecl.php.net/package/...
    The second is: https://pecl.php.net/package/...
    The first official reminder: This package has been superseded, but it is still maintained for bugs and security fixes, has been abandoned, but bugs and security issues will continue to repair, does not support PHP7.

    Recommendations:

    Write at the end:
    If you study by yourself, you should recommend yum installation, because there will be a lack of dependencies during the installation process.

    Posted by Ionisis on Thu, 11 Jul 2019 17:04:13 -0700