当前位置
➜ bin pwd
/usr/local/opt/php@7.1/bin
1.下载扩展
➜ bin wget http://pecl.php.net/get/mongodb-1.5.5.tgz
--2019-08-15 10:21:04-- http://pecl.php.net/get/mongodb-1.5.5.tgz
Resolving pecl.php.net... 104.236.228.160
Connecting to pecl.php.net|104.236.228.160|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 1060017 (1.0M) [application/octet-stream]
Saving to: ‘mongodb-1.5.5.tgz’
mongodb-1.5.5.tgz 100%[=========================================================================>] 1.01M 15.8KB/s in 50s
2019-08-15 10:21:55 (20.8 KB/s) - ‘mongodb-1.5.5.tgz’ saved [1060017/1060017]
2.解压安装包
➜ bin tar -zxvf mongodb-1.5.5.tgz
➜ bin ls
mongodb-1.5.5 package.xml peardev phar php php-config phpize
mongodb-1.5.5.tgz pear pecl phar.phar php-cgi phpdbg
➜ bin pwd
/usr/local/opt/php@7.1/bin
3.进入解压目录,运行phpize,为安装扩展准备环境
➜ bin cd mongodb-1.5.5
➜ mongodb-1.5.5 /usr/local/opt/php@7.1/bin/phpize
4.安装编译mongodb的php扩展
第3步执行完成后,在当前目录下就生成了configure文件。接下来,使用./configure命令进行安装配置;
然后,使用make && make install进行编译安装,命令如下:
➜ ./configure --with-php-config=/usr/local/opt/php@7.1/bin/php-config
➜ make && make install
Build complete.
Don't forget to run 'make test'.
mkdir: /usr/local/Cellar/php@7.1/7.1.27/pecl: File exists
mkdir: /usr/local/Cellar/php@7.1/7.1.27/pecl: No such file or directory
make: *** [install-modules] Error 1
5. 报错了修改 vi /usr/local/opt/php@7.1/bin/php-config 参考文章
修改 extension_dir='/usr/local/Cellar/php@7.1/7.1.27/pecl/20160303' => extension_dir='/usr/local/Cellar/php@7.1/7.1.27/lib/'
➜ mongodb-1.5.5 pwd
/usr/local/opt/php@7.1/bin/mongodb-1.5.5
6.重新编译
./configure --with-php-config=/usr/local/opt/php@7.1/bin/php-config
make && make install
➜ mongodb-1.5.5 ./configure --with-php-config=/usr/local/opt/php@7.1/bin/php-config
➜ mongodb-1.5.5 make && make install
Build complete.
Don't forget to run 'make test'.
Installing shared extensions: /usr/local/Cellar/php@7.1/7.1.27/lib//
7.添加mongodb扩展
编辑php.ini [vi /usr/local/etc/php/7.1/php.ini],在extension区域添加mongodb扩展
extension=/usr/local/Cellar/php@7.1/7.1.27/lib/mongodb.so
8.重启服务
brew services restart php71
PS
#下载文件目录
/usr/local/opt/php71/bin/mongodb-1.5.5
#扩展目录
/usr/local/Cellar/php@7.1/7.1.27/lib
# 查看PHP扩展包存储目录
# php -i | grep extension_dir
#查看PHP的mongodb扩展模块是否已经成功安装
php -m | grep mongodb