Summary of PHP installation extension methods in CentOS system, centosphp
CentOS
PHP has multiple ways to install extensions, mainly includingPackage Management
OfInstall yum
,Pecl Installation
, AndSource code compilation and Installation
.
Package Management
Is particularly convenient, andSource code compilation
To facilitate parameter optimization.
Recommendation for building a local development environmentPackage Management
To save time. WhileOnline deployment
Recommended for EnvironmentsCompile and install
To facilitate optimization.
This document usesMongoDB
Extension 'installation example.
Tools
PHP version: 7.0.17
Nginx: 1.10.2
VMware Version: 12.0.0
CentOS version: 7.0
1. Install yum
Yum Method
Install and configure the. so dynamic library that can automatically install the extensionphp.ini
Note:
Make sure youYum Source
There are corresponding extensions
Restart the server after installation.Nginx
OrApache
Browser accessindex.php
File, outputphpinfo
Information, if anyMongoDB
Information, the installation is successful
[Root @ localhost ~] Yum search mongodb | grep php # search for MongoDB extensions in the yum source [root @ localhost ~] Yum-y install php70w-pecl-mongo # install MongoDB extension for the PHP version [root @ localhost ~] Systemctl restart nginx # restart Nginx
Ii. Install pecl
Official documents: http://php.net/manual/zh/mong...
[Root @ localhost ~] # Pecl install mongodb-bash: pecl: Command not found
Enter directlypecl install mongodb
An error is reported.pecl
We have not installed or installedpecl
[root@localhost ~]# yum -y install php70w-pear[root@localhost ~]# pecl install mongodbconfigure: error: Cannot find OpenSSL's <evp.h>ERROR: `/var/tmp/mongodb/configure --with-php-config=/usr/bin/php-config' failed
At this stepError
, We need to installopenssl
After the installation is complete, continue to run the previousNot executed successfully
Command
[Root @ localhost ~] # Yum-y install openssl-devel [root @ localhost ~] # Pecl install mongodb [root @ localhost ~] # Systemctl restart nginx # restart Nginx
After the installation is completePHP
Configuration Filephp.ini
LoadMongoDB
Extension
Restart the server after installation.Nginx
OrApache
Browser accessindex.php
File, outputphpinfo
Information, if anyMongoDB
Information, the installation is successful
Iii. source code compilation and Installation
Source code compilation package download list: https://pecl.php.net/packages.php
Mongodb package: https://pecl.php.net/package/mongodb
[Root @ localhost ~] # Wget http://pecl.php.net/get/mongodb-1.2.8.tgz # download the source package [root @ localhost ~] # Tar zxf mongodb-1.2.8.tgz # extract [root @ localhost ~] # Cd mongodb-1.2.8 # may be/usr/local/php/bin/phpize find your own phpize file, php-config similarly [root @ localhost mongodb-1.2.8] #/usr/bin/phpize login ing 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-configconfigure: error: Cannot find OpenSSL's <evp. h>
In this stepIt's a taste of familiarity and a feeling of familiarity.
, We need to installopenssl
After the installation is complete, continue to run the previousNot executed successfully
Command
[Root @ localhost mongodb-1.2.8] # yum-y install openssl-devel [root @ localhost mongodb-1.2.8] #. /configure -- with-php-config =/usr/bin/php-config # Make sure that you have installed gcc ++. If you have not installed yum-y install gcc ++ [root @ localhost mongodb-1.2.8] # make & make install # compile
Note:php-config
Is a simple command line scriptObtain
InstalledPHP configuration
.
If multiple PHP versions are installed during compilation extension, you can use--with-php-config
Option to specify which version to compile. This option specifies the correspondingphp-config
Script path.
Compiled successfully
For example
In this casePHP
Configuration Filephp.ini
LoadMongoDB
Extension
Restart the serverNginx
OrApache
Browser accessindex.php
File, outputphpinfo
Information, if anyMongoDB
Information, the installation is successful
[Root @ localhost mongodb-1.2.8] # systemctl restart nginx # restart Nginx
Summary:
Pecl Installation
AndSource code compilation and Installation
The difference is that the latter is more convenient for parameter optimization.
In the selectMongo Extension
The official website provides two types:mongo
Andmongodb
First: https://pecl.php.net/package/mongo
2: https://pecl.php.net/package/mongodb
First official prompt:This package has been superseded, but is still maintained for bugs and security fixes
, Has been abandoned,bug
Andsecurity
Problems will continue to be fixed, not supportedPHP7
.
Suggestion:
PHP 5.x is recommended.mongo
Extension
PHP version 7.x is recommendedmongodb
Extension
PHP5.x can be usedmongodb
Extension. However, PHP7.x cannot be used.mongo
Extension.
Conclusion:
If you are learning by yourself, it is recommended.Install yum
Because it will appear during your installationLack of various Dependencies
OfError
.