1. 安装 homebrew

  2. 确定已安装 pkg-config

1$ where pkg-config
2/usr/local/bin/pkg-config

若提示

1pkg-config not found

则先使用 brew install pkg-config 进行安装

  1. 安装最新的 OpenSSL

macOS 默认的 OpenSSL 版本太低,编译时需要版本高于1.0.1才可,so just install the lastest one.

 1$ brew install openssl
 2==> Downloading https://homebrew.bintray.com/bottles/openssl-1.0.2l.sierra.bottle.tar.gz
 3Already downloaded: /Users/mrasong/Library/Caches/Homebrew/openssl-1.0.2l.sierra.bottle.tar.gz
 4==> Pouring openssl-1.0.2l.sierra.bottle.tar.gz
 5==> Using the sandbox
 6==> Caveats
 7A CA file has been bootstrapped using certificates from the SystemRoots
 8keychain. To add additional certificates (e.g. the certificates added in
 9the System keychain), place .pem files in
10  /usr/local/etc/openssl/certs
11
12and run
13  /usr/local/opt/openssl/bin/c_rehash
14
15This formula is keg-only, which means it was not symlinked into /usr/local,
16because Apple has deprecated use of OpenSSL in favor of its own TLS and crypto libraries.
17
18If you need to have this software first in your PATH run:
19  echo 'export PATH="/usr/local/opt/openssl/bin:$PATH"' >> ~/.zshrc
20
21For compilers to find this software you may need to set:
22    LDFLAGS:  -L/usr/local/opt/openssl/lib
23    CPPFLAGS: -I/usr/local/opt/openssl/include
24For pkg-config to find this software you may need to set:
25    PKG_CONFIG_PATH: /usr/local/opt/openssl/lib/pkgconfig
26
27==> Summary
28  /usr/local/Cellar/openssl/1.0.2l: 1,709 files, 12.2MB

安装完成后,需要给环境变量里面加入一些东西,上面的提示已经说的很清楚。

vi ~/.zshrc 或者 vi ~/.bash_profile

添加以下内容

1export PATH=/usr/local/opt/openssl/bin:$PATH
2export LDFLAGS="-L/usr/local/opt/openssl/lib"
3export CPPFLAGS="-I/usr/local/opt/openssl/include"
4export PKG_CONFIG_PATH="/usr/local/opt/openssl/lib/pkgconfig"

source ~/.zshrc 或者 source ~/.bash_profile

  1. pecl 安装 mongodb.so
1pecl install mongodb
  1. 修改 php.ini,加入 extension=mongodb.so,重启服务,完成。