2016-06-08 15:18
浏览 157

使用MacPorts在Mac OS X 10.11上安装MongoDB

I am trying to install MongoDB on my computer running Mac OS X 10.11 (El Capitan).

My Apache + PHP configuration was already working correctly.

I installed MongoDB and PHP drivers for MongoDB through MacPorts:

sudo port install mongodb
sudo port install php55-mongodb

Installation ran correctly.

I added file to the extensions loaded in the php.ini file:


When I run phpinfo() function in php file, mongodb extension seems to be loaded correctly: enter image description here

I tried to test my connexion by initializing a MongoClient instance:


    $mongoDB = new MongoClient();



Unfortunately, I got a HTTP ERROR 500, and I got the following line in my Apache logs:

PHP Fatal error:  Class 'MongoClient' not found in ...

Did I make something wrong ?

图片转代码服务由CSDN问答提供 功能建议

我正在尝试在运行Mac OS X 10.11(El Capitan)的计算机上安装MongoDB。 \ n

我的Apache + PHP配置已经正常工作。


 <  code> sudo port install mongodb 
sudo port install php55-mongodb 


我添加了 文件到php.ini文件中加载的扩展名:

  extension = / opt / local / lib / php55 / extensions / no-debug-non-zts-20121212 / mongodb  .so 



 $ mongoDB = 新的MongoClient(); 
 \  n var_dump($ mongoDB); 

不幸的是,我得到了一个 HTTP ERROR 500 ,我得到了 我的Apache日志中的以下行:



  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • dongtun3328 2016-06-09 17:48

    Finally found a solution to my problem.

    As @neverpanic and @Zagonine made me understand, php-mongodb and php-mongo are not the same extension.

    If you want to use old PHP driving classes, you should use php-mongo package instead of the very new php-mongodb.

    Trying to install latest php-mongo extension, I had an other problem related to OpenSSL. To bypass it, I installed an old version of php-mongo extension:

    sudo /usr/local/pear/bin/pecl install mongo-1.5.8

    Hopefully it will help someone else.

    打赏 评论
  • dsbezji539113152 2016-06-08 16:25

    On most of site I saw you need to add the extension and not in your php.ini.
    If it's not solved your problem, I recommand you to install MongoDB Drive with PELC.

    Run command line:

    $ sudo pecl install mongo

    And add this line to your php.ini:

    Doc Mongo Installation

    打赏 评论

相关推荐 更多相似问题