Summary of PHP installation extension methods in CentOS system, centosphp
CentOSPHP has multiple ways to install extensions, mainly includingPackage ManagementOfInstall yum,Pecl Installation, AndSource code compilation and Installation.
Package ManagementIs particularly convenient, andSource code compilationTo facilitate parameter optimization.
Recommendation for building a local development environmentPackage ManagementTo save time. WhileOnline deploymentRecommended for EnvironmentsCompile and installTo facilitate optimization.
This document usesMongoDBExtension '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 MethodInstall and configure the. so dynamic library that can automatically install the extensionphp.ini
Note:
Make sure youYum SourceThere are corresponding extensions
Restart the server after installation.NginxOrApache
Browser accessindex.phpFile, outputphpinfoInformation, if anyMongoDBInformation, 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 mongodbAn error is reported.peclWe 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 installopensslAfter the installation is complete, continue to run the previousNot executed successfullyCommand
[Root @ localhost ~] # Yum-y install openssl-devel [root @ localhost ~] # Pecl install mongodb [root @ localhost ~] # Systemctl restart nginx # restart Nginx
After the installation is completePHPConfiguration Filephp.iniLoadMongoDBExtension
Restart the server after installation.NginxOrApache
Browser accessindex.phpFile, outputphpinfoInformation, if anyMongoDBInformation, 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 installopensslAfter the installation is complete, continue to run the previousNot executed successfullyCommand
[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-configIs a simple command line scriptObtainInstalledPHP configuration.
If multiple PHP versions are installed during compilation extension, you can use--with-php-configOption to specify which version to compile. This option specifies the correspondingphp-configScript path.
Compiled successfullyFor example
In this casePHPConfiguration Filephp.iniLoadMongoDBExtension
Restart the serverNginxOrApache
Browser accessindex.phpFile, outputphpinfoInformation, if anyMongoDBInformation, the installation is successful
[Root @ localhost mongodb-1.2.8] # systemctl restart nginx # restart Nginx
Summary:
Pecl InstallationAndSource code compilation and InstallationThe difference is that the latter is more convenient for parameter optimization.
In the selectMongo ExtensionThe official website provides two types:mongoAndmongodb
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,bugAndsecurityProblems will continue to be fixed, not supportedPHP7.
Suggestion:
PHP 5.x is recommended.mongoExtension
PHP version 7.x is recommendedmongodbExtension
PHP5.x can be usedmongodbExtension. However, PHP7.x cannot be used.mongoExtension.
Conclusion:
If you are learning by yourself, it is recommended.Install yumBecause it will appear during your installationLack of various DependenciesOfError.