-
安装 homebrew
-
确定已安装
pkg-config
$ where pkg-config
/usr/local/bin/pkg-config
若提示
pkg-config not found
则先使用 brew install pkg-config
进行安装
- 安装最新的
OpenSSL
macOS 默认的 OpenSSL
版本太低,编译时需要版本高于1.0.1
才可,so just install the lastest one.
$ brew install openssl
==> Downloading https://homebrew.bintray.com/bottles/openssl-1.0.2l.sierra.bottle.tar.gz
Already downloaded: /Users/mrasong/Library/Caches/Homebrew/openssl-1.0.2l.sierra.bottle.tar.gz
==> Pouring openssl-1.0.2l.sierra.bottle.tar.gz
==> Using the sandbox
==> Caveats
A CA file has been bootstrapped using certificates from the SystemRoots
keychain. To add additional certificates (e.g. the certificates added in
the System keychain), place .pem files in
/usr/local/etc/openssl/certs
and run
/usr/local/opt/openssl/bin/c_rehash
This formula is keg-only, which means it was not symlinked into /usr/local,
because Apple has deprecated use of OpenSSL in favor of its own TLS and crypto libraries.
If you need to have this software first in your PATH run:
echo 'export PATH="/usr/local/opt/openssl/bin:$PATH"' >> ~/.zshrc
For compilers to find this software you may need to set:
LDFLAGS: -L/usr/local/opt/openssl/lib
CPPFLAGS: -I/usr/local/opt/openssl/include
For pkg-config to find this software you may need to set:
PKG_CONFIG_PATH: /usr/local/opt/openssl/lib/pkgconfig
==> Summary
/usr/local/Cellar/openssl/1.0.2l: 1,709 files, 12.2MB
安装完成后,需要给环境变量里面加入一些东西,上面的提示已经说的很清楚。
vi ~/.zshrc
或者 vi ~/.bash_profile
添加以下内容
export PATH=/usr/local/opt/openssl/bin:$PATH
export LDFLAGS="-L/usr/local/opt/openssl/lib"
export CPPFLAGS="-I/usr/local/opt/openssl/include"
export PKG_CONFIG_PATH="/usr/local/opt/openssl/lib/pkgconfig"
source ~/.zshrc
或者 source ~/.bash_profile
pecl
安装mongodb.so
pecl install mongodb
- 修改
php.ini
,加入extension=mongodb.so
,重启服务,完成。