如何在Mac OS X Yosemite上安装MongoDB PHP驱动?PECL安装报错求助
Hey there, let's work through this MongoDB PHP driver issue step by step. The compile error you're hitting with sudo pecl install mongodb is almost certainly tied to missing dependencies or misconfigured compiler paths—totally expected after Homebrew removed those old MongoDB-related files. Here's how to fix it:
Install core dependencies first
The PHP MongoDB driver relies onlibmongocandlibbsonunder the hood, which Homebrew probably cleared out. Let's reinstall them directly:brew install libmongoc libbsonThis will grab the latest versions of these libraries and their header files, which your compiler was missing in the error log.
Point the compiler to the right paths
We need to tell the system where to find the configuration files for those new libraries. Run this in your terminal to set the temporary environment variable (add it to~/.zshrcor~/.bash_profilelater if you want it permanent):export PKG_CONFIG_PATH="$(brew --prefix)/lib/pkgconfig"Re-run the PECL install (without sudo!)
Usingsudocan mess up Homebrew's file permissions, so skip it this time. Try installing the driver again:pecl install mongodbIf you still hit snags, explicitly tell the compiler where the libraries live with this command:
pecl install mongodb --with-mongodb=$(brew --prefix libmongoc)Verify the extension works
After installation finishes, check if the driver is loaded by running:php -i | grep mongodbIf you don't see any output, manually add
extension=mongodb.soto yourphp.inifile. You can find yourphp.inipath withphp --ini.Fix version mismatches (if needed)
If you're using a specific PHP version (like PHP 8.1 instead of the system default), make sure you're using the matchingpeclcommand. For example, if you installedphp@8.1via Homebrew:brew services start php@8.1 /usr/local/opt/php@8.1/bin/pecl install mongodb
内容的提问来源于stack exchange,提问作者Kwame

