简体   繁体   中英

MongoClient class not found with MAMP

  • I have downloaded and installed MongoDB.
  • I can interact with my db via the mongo shell.
  • I have installed the PHP extension through sudo pecl install mongo
  • I confirmed that mongo.so is in the folder defined by extension_dir in php.ini.
  • I have confirmed that extension=mongo.so is defined in php.ini.
  • I confirmed that the php.ini file I edited is the php.ini file being loaded for configuration via phpinfo() .

Yet when I try to instantiate a new MongoClient, my script fails silently. And I when I try to run a command like php --rc MongoClient , I receive an error that the class does not exist. I have restarted apache (MAMP) and the computer and reverified config files multiple times. As I can use mongodb and mongo, I assume this is a PHP configuration issue, but I've double checked config multiple times. Any ideas?

Edit: php_error.log output:

[20-Aug-2014 18:54:03 Europe/Berlin] PHP Fatal error: Class 'MongoClient' not found in /Applications/MAMP/htdocs/pantry/application/controllers/mongodb.php on line 14

[20-Aug-2014 18:54:56 Europe/Berlin] PHP Warning: PHP Startup: mongo: Unable to initialize module

Module compiled with module API=20100525

PHP compiled with module API=20121212

These options need to match in Unknown on line 0

The issue now is clear, but I do not how to resolve it.

Alright - so the final solution was hinted at around other similar questions. I had everything in the right place, using the right PHP, mongo, etc, but phpize was still configured with the wrong api version. So I downloaded the latest version of the applicable PHP source code, stuffed it all in /Applications/MAMP/bin/php/php5.5.10/include/php, reran pecl, restarted apache, and am good to go.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM