Laravel 4:找不到类"MongoClient" [英] Laravel 4: Class 'MongoClient' Not Found
问题描述
我在WAMP上安装了Laravel 4,它非常适合MySQL后端.
I have Laravel 4 installed on WAMP and it works great with a MySQL backend.
我已经成功设置了第二个虚拟主机,并且想使用MongoDB
后端.在四处搜寻之后,我发现Laravel本身并没有连接到MongoDB,我发现 https://github.com/jenssegers/Laravel-MongoDB ,我一直在尝试进行设置,但似乎无法正确完成.显然,我一定做错了事,希望有人能帮助我确定我做错了什么.
I have successfully setup second virtual host and would like to use a MongoDB
backend. After searching around I found out that Laravel does not natively connect to MongoDB and I found https://github.com/jenssegers/Laravel-MongoDB and I have been trying to set it up but I can't seem to get it right. Obviously I must be doing something wrong and I am hoping someone can help me identify what it is that I am not doing right.
我按照说明编辑了composer.json
:
............
"license": "MIT",
"require": {
"laravel/framework": "4.1.*",
"jenssegers/mongodb": "*"
},
"autoload": {
.........
然后我运行了composer update
.它成功安装了monolog 1.9.1和swiftmailer v5.2.0(无论它们是什么)(几天前),但是之后又抛出了错误.今天,我尝试再次运行composer update
,它将composer update
分别更新为1.10.0和v5.2.1,然后遇到相同的错误.现在,当我尝试composer update
时,它始终会抛出相同的错误:
Then I ran composer update
. It installed monolog 1.9.1 and swiftmailer v5.2.0 - whatever these are - successfully (a few days ago) but then threw an error after that. Today I tried to run composer update
again, and it updated the two to 1.10.0 and v5.2.1 respectively and then encountered the same error. Now when I try composer update
it consistently throws the same error:
Nothing to install or update
Generating autoload files
{"error":{"type":"Symfony\\Component\\Debug\\Exception\\FatalErrorException","me
ssage":"Class 'MongoClient' not found","file":"C:\\wamp\\www\\laravel\\vendor\\j
enssegers\\mongodb\\src\\Jenssegers\\Mongodb\\Connection.php","line":132}}Script
php artisan clear-compiled handling the post-update-cmd event returned with an
error
[RuntimeException]
Error Output:
update [--prefer-source] [--prefer-dist] [--dry-run] [--dev] [--no-dev] [--lock]
[--no-plugins] [--no-custom-installers] [--no-scripts] [--no-progress] [--with-
dependencies] [-v|vv|vvv|--verbose] [-o|--optimize-autoloader] [packages1] ... [
packagesN]
我尝试过的事情:
我已经下载并安装了php_mongo.dll,方法是将其放在php ext文件夹中,并在php.ini中启用它:
I have downloaded and installed the php_mongo.dll by placing it in the php ext folder and enabling it in php.ini:
; added for mongoDB connections
extension=php_mongo.dll
但这没有帮助.
推荐答案
注意:如果没有@Hassan的帮助,我将无法完全解决问题-请参阅@下方的评论哈桑的答案.
NOTE: I would not have been able to resolve the issue completely without @Hassan 's help -- please see comments under @Hassan 's answer.
我将提供此答案,希望它可以帮助可能遇到相同问题的其他人.我认为最好给出答案以使其突出.
I'll provide this answer in the hopes that it may help someone else who may experience the same issue. I thought it better to give it as an answer so that it stands out.
进一步的搜索将我引到这里: https://github.com/jenssegers/Laravel-MongoDB/issues/36
然后在这里: https://github.com/leroy-merlin-br/mongolid-laravel#troubleshooting
以下命令和输出指示我应该使用php_mongo.dll
扩展名更新的php.ini
的位置:
Further search lead me here: https://github.com/jenssegers/Laravel-MongoDB/issues/36
Then here: https://github.com/leroy-merlin-br/mongolid-laravel#troubleshooting
The following command and output indicates the location of php.ini
that I should have updated with the php_mongo.dll
extension:
$ php -i | grep 'Configuration File'
Configuration File (php.ini) Path => C:\Windows
Loaded Configuration File => C:\wamp\bin\php\php5.5.12\php.ini
但是WAMP
托盘图标指向C:\wamp\bin\apache2.4.9\bin\php.ini
-这是我更新的内容.我还通过在显示的输出中运行以下命令来检查CLI环境中的PHP是否正确导入了驱动程序:
The WAMP
tray icon however points to C:\wamp\bin\apache2.4.9\bin\php.ini
-- which is what I had updated. I also checked if PHP in the CLI environment is importing the driver properly by running the following command with the output shown:
$ php -i | grep 'Mongo'
MongoDB Support => enabled
更新正确的php.ini
之后,我restarted apache
并再次尝试
After updating the correct php.ini
, I restarted apache
and tried again composer update
again. The error was different -- authentication -- as the username, password and database were wrong. Once those were corrected, the update completed without incident.
这篇关于Laravel 4:找不到类"MongoClient"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!