This article gives you a summary of the CentOS system in the installation of the expansion of the way, the main package management of the Yum installation, pecl installation, and source code compilation and installation. Summary of the very comprehensive, recommended to everyone.
CentOS
Under, PHP has several ways to install extensions, mostly, 包管理式
and yum 安装
pecl 安装
源码编译安装
.
包管理式
Loading and unloading is especially convenient, while 源码编译式
the installation is convenient for parameter tuning.
Generally build the recommended installation of the local development environment 包管理式
, save time. And the 线上部署
environment is recommended 编译安装
, convenient tuning.
This article takes an MongoDB
extended ' installation example.
Tools
PHP Version: 7.0.17
nginx:1.10.2
VMware version number: 12.0.0
CentOS Version: 7.0
One, yum installation
yum 方式
Install the. So dynamic library that automatically installs the extension and configures itphp.ini
Note:
Make sure you yum 源
have a corresponding extension within yourself.
Restart the server after installation is complete Nginx
orApache
The browser accesses the index.php
file, outputs the phpinfo
information, and if there is MongoDB
information, the installation succeeds
[root@localhost ~]yum Search mongodb|grep php # search Yum source inside MongoDB extension [root@localhost ~]yum-y install Php70w-pecl-mong o # Install PHP corresponding version of MongoDB extension [root@localhost ~]systemctl restart Nginx # reboot Nginx
Second, PECL installation
Official Document: Http://php.net/manual/zh/mong ...
[root@localhost ~]# pecl Install mongodb-bash:pecl: Command not found
Direct input pecl install mongodb
will be an error stating that pecl
we have not installed, installedpecl
[root@localhost ~]# yum-y Install php70w-pear[root@localhost ~]# pecl install mongodbconfigure:error:Cannot find Openss L ' s <evp.h>error: '/var/tmp/mongodb/configure--with-php-config=/usr/bin/php-config ' failed
At this point 报错
, we will need to install openssl
and continue to execute the last command after 未执行成功
the installation is complete.
[root@localhost ~]# yum-y install OpenSSL openssl-devel[root@localhost ~]# pecl install mongodb[root@localhost ~]# system CTL Restart Nginx # restart Nginx
PHP
php.ini
load extension in config file after installation is MongoDB
complete
Restart the server after installation is complete Nginx
orApache
The browser accesses the index.php
file, outputs the phpinfo
information, and if there is MongoDB
information, the installation succeeds
Third, source code compilation and installation
Source code compilation package Download list: https://pecl.php.net/packages.php
MongoDB Package Download Address: Https://pecl.php.net/package/mongodb
[Root@localhost ~]# wget http://pecl.php.net/get/mongodb-1.2.8.tgz #下载源码包 [root@localhost ~]# tar zxf mongodb-1.2.8.tgz #解压 [root@localhost ~]# cd mongodb-1.2.8# may be/usr/local/php/bin/phpize find its own phpize file, php-config the same [root@localhost mongodb-1.2.8]#/usr/bin/phpize Configuring for:php API Version: 20151012Zend Module API No: 20151012Zend 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>
At this point 又是熟悉的味道又是熟悉的感觉
, we need to install openssl
and continue to execute the last command after the installation is complete. 未执行成功
[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 have GCC gcc++ installed yum-y install gcc gcc++[root@localhost mongodb-1.2.8]# Mak e && make install # Compile
Description: php-config
is a simple command-line script for the 获取
information that is installed PHP 配置
.
When compiling extensions, if you have more than one version of PHP installed, you can use the --with-php-config
option to specify which version to use when configuring, which specifies the path of the corresponding php-config
script.
编译成功
Such as
The extension is now loaded in the PHP
configuration file php.ini
MongoDB
Restart the server Nginx
orApache
The browser accesses the index.php
file, outputs the phpinfo
information, and if there is MongoDB
information, the installation succeeds
[root@localhost mongodb-1.2.8]# systemctl Restart Nginx # restart Nginx
Summarize:
pecl 安装
The 源码编译安装
difference is that the latter is more convenient for parameter tuning.
At the Mongo 扩展
time of choice, the official offers two kinds: mongo
andmongodb
The first type: Https://pecl.php.net/package/mongo
The second type: Https://pecl.php.net/package/mongodb
The first official tip: This package has been superseded, but is still maintained for bugs and security fixes
, has been abandoned, but bug
security
the problems and aspects will continue to repair, not support PHP7
.
Suggestions:
PHP version for 5.x recommended mongo
extension
PHP version for 7.x recommended mongodb
extension
php5.x can use mongodb
extensions. However, php7.x can not use mongo
extensions.
Written at the end:
If you are learning, it is recommended yum 安装
, because you will appear 缺少各种依赖
报错
during the installation process