去下载 https://pecl.php.net/package/mongodb 需要对应的版本
解压 mongodb 下载包,进入到文件目录中
![](https://img.haomeiwen.com/i13488063/7ac2700883813034.png)
你php安装路径中到 phpize 用于安装php扩展使用
/usr/local/Cellar/php/7.2.9_2/bin/phpize
编译前配置文件检测准备工作 执行下面命令
./configure --with-php-config=/usr/local/Cellar/php/7.2.9_2/bin/php-config
注意 ==》/usr/local/Cellar/php/7.2.9_2/bin/php-config (是你自己的php 目录下面bin/php-config)
./configure --with-php-config=/usr/local/Cellar/php/7.2.9_2/bin/php-config --with-openssl-dir=/usr/local/Cellar/openssl/1.0.2p
// --with-openssl-dir=/usr/local/Cellar/openssl/1.0.2p ==》 需要依赖openssl 这个版本需要大于1.0的所以你本机如果openssl 版本低则自己更新或者重新安装openssl
mac 机器 brew openssl 命令
![](https://img.haomeiwen.com/i13488063/b1ba1ac53c31525c.png)
接下来开始编译 安装了
sudo make
![](https://img.haomeiwen.com/i13488063/36b489d3684071e7.png)
sudo make install
![](https://img.haomeiwen.com/i13488063/4311c0f9104f5910.png)
到这基本就安装成功了mongodb扩展mongodb.so 文件了 ,在目录 /usr/local/Cellar/php7.2.9_2/pel/20170718/目录中
![](https://img.haomeiwen.com/i13488063/dfbccb9fc58314fc.png)
最后配置你到php.ini 添加下面一行代码
extension=mongodb.so
![](https://img.haomeiwen.com/i13488063/caf1eb0bfda19d3b.png)
php -m 命令 查看是否有成功有mongodb 扩展
![](https://img.haomeiwen.com/i13488063/87949265f51f0035.png)
安装成功了 有mongodb模块。 你也可以通过 phpinfo() 方法查看。
网友评论