douman6679 2015-02-05 06:45
浏览 103
已采纳

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

I have a site using Apache that is just the following code:

<?php $m = new MongoClient(); ?>

and when I try to access it, I get the error in error.log

`PHP Fatal Error: Class 'MongoClient' not found`

The following are settings which might be wrong, but I don't think are.

php -i | grep 'Configuration' => Configuration File (php.ini) Path => /etc/php5/cli | Loaded Configuration File => /etc/php5/cli/php.ini

grep 'mongo' /etc/php5/cli/php.ini => extension=mongo.so

php -i | grep 'extension' => extension_dir => /usr/lib/php5/20121212 => /usr/lib/php5/20121212

ls /usr/lib/php5/20121212/ | grep 'mongo.so' => mongo.so

I haven't been able to find anything to suggest I installed it wrong or have it wrongly configured. I installed it within the past two hours using pecl and pear (sudo pear install -f pecl/mongo and sudo pecl install mongo)

I've restarted my Apache and even my computer multiple times.

So why am I getting the error Class 'MongoClient' not found?

I'm on Ubuntu. PHP version 5.5.

Edit: I've just discovered that MongoClient is valid when I run php in interactive mode. Perhaps it has to do with a user permission/user installation issue?

  • 写回答

2条回答 默认 最新

  • dpd7122 2015-02-05 19:48
    关注

    The problem was that I was using php -i | grep 'Configuration' to find the .ini file. This lead to /etc/php5/cli/php.ini. In retrospect, this should have been an obvious giveaway: cli means command line interface, basically for the interpreter. What I needed was the ini file that Apache was using.

    Unfortunately, there was no great way to do this as I couldn't log into the www-data user, but I made a file that had the code

    <?php
      phpinfo();
    ?>
    

    and that revealed that the .ini file location was actually /etc/php5/apache2/php.ini.

    Once I updated that ini file with extension=mongo.so, the module was loaded at startup, so I restarted and everything is working now.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?