dongyi3616
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 mongodb.so file to the extensions loaded in the php.ini file:

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

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:

<?php

    $mongoDB = new MongoClient();

    var_dump($mongoDB);

?>

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配置已经正常工作。

我通过MacPorts为MongoDB安装了MongoDB和PHP驱动程序:

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

安装正确运行。

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

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

当我在php文件中运行phpinfo()函数时,mongodb扩展似乎正确加载:

我尝试通过初始化MongoClient实例来测试我的连接:

 &lt;?php 
 
 $ mongoDB = 新的MongoClient(); 
 \  n var_dump($ mongoDB); 
 
?&gt; 
   
 
 

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

  PHP致命错误:在...... 
   
 
中找不到类'MongoClient'  

我做错了吗?

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

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 mongo.so and not mongodb.so 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:

    extension=mongo.so
    

    Doc php.net Mongo Installation

    打赏 评论

相关推荐 更多相似问题