一、环境信息
| 配置 | 信息 |
|---|---|
| PHP版本 | PHP Version # 7.4.28 |
| Loaded Configuration File | /opt/homebrew/etc/php/7.4/php.ini |
足够了,MAC相对比较简单,需要知道php.ini的路径。
二、下载压缩包
进入mongodb扩展包下载管理 ![压缩包下载]
与windows不同的是,这里是需要点击对应版本的.tgz链接下载。 比如,我的版本比较新,这里我们下载mongodb-1.13.1版本,我们需要点击mongodb-1.13.0.tgz (1406.5kB)对应的链接进行下载。
三、编译安装
- 解压下载文件 解压下载文件并放置到
/opt/homebrew/lib/php/pecl/20190902/目录中
2. 进入mongodb目录
cd mongodb-1.13.0
-
执行
phpize扩展php扩展模块
phpize
- 软件编译
./configure
正常的情况会有以下的输出
AppledeMacBook-Pro:mongodb-1.9.1 houxin$ ./configure
checking for grep that handles long lines and -e... /usr/bin/grep
checking for egrep... /usr/bin/grep -E
checking for a sed that does not truncate output... /usr/bin/sed
checking for pkg-config... /usr/local/bin/pkg-config
checking pkg-config is at least version 0.9.0... yes
checking for cc... cc
...
config.status: creating /usr/local/mongodb-1.9.1/src/libmongoc/src/libmongoc/src/mongoc/mongoc-version.h
config.status: creating /usr/local/mongodb-1.9.1/src/libmongocrypt/src/mongocrypt-config.h
config.status: creating /usr/local/mongodb-1.9.1/src/libmongocrypt/src/mongocrypt.h
config.status: creating config.h
复制代码
- 安装
make && make install
正确的情况,会有以下的输出
Build complete.
Don't forget to run 'make test'.
Installing shared extensions: /opt/homebrew/Cellar/php@7.4/7.4.28_1/pecl/20190902/
6.修改PHP配置文件
根据环境的信息可知,php.ini的路径是/opt/homebrew/etc/php/7.4/php.ini。 修改php.ini,添加mongodb.so,只需要添加mongodb即可。
extension=mongodb
7.重启PHP
brew services restart php@7.4
再次打开phpinfo,发现mongodb扩展已经加载。