PHP 致命错误:找不到“MongoClient"类 [英] PHP Fatal Error: Class 'MongoClient' not found

查看:39
本文介绍了PHP 致命错误:找不到“MongoClient"类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用 Apache 的网站,代码如下:

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

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

当我尝试访问它时,我在 error.log 中收到错误

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 '配置' => 配置文件(php.ini)路径 =>/etc/php5/cli |加载的配置文件 =>/etc/php5/cli/php.ini

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

<代码>php -i |grep '扩展' =>extension_dir =>/usr/lib/php5/20121212 =>/usr/lib/php5/20121212

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

我找不到任何迹象表明我安装错误或配置错误.我在过去两个小时内使用 peclpear(sudo pear install -f pecl/mongosudo pecl install mongo)

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)

我已经多次重启我的 Apache 甚至我的电脑.

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

那么为什么我会收到错误Class 'MongoClient' not found?

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

我在 Ubuntu 上.PHP 5.5 版.

I'm on Ubuntu. PHP version 5.5.

我刚刚发现当我在交互模式下运行 php 时 MongoClient 是有效的.也许这与用户权限/用户安装问题有关?

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?

推荐答案

问题是我使用的是 php -i |grep 'Configuration' 找到 .ini 文件.这导致 /etc/php5/cli/php.ini.回想起来,这应该是一个明显的赠品:cli 表示命令行界面,主要用于解释器.我需要的是 Apache 使用的 ini 文件.

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.

不幸的是,没有很好的方法可以做到这一点,因为我无法登录到 www-data 用户,但我制作了一个包含代码的文件

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();
?>

这表明 .ini 文件位置实际上是 /etc/php5/apache2/php.ini.

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

一旦我用 extension=mongo.so 更新了那个 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.

这篇关于PHP 致命错误:找不到“MongoClient"类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆