Question

I'm trying to set up MongoDB with PHP and WAMP. I had WAMP 64 bit installed previously, but I see that the PHP drivers don't work with that, so I uninstalled it and installed 32 bit. I downloaded the PHP drivers from here: http://downloads.mongodb.org/mongo-latest-php5.3vc9ts.zip, put the dll in ext and added the extension in my php.ini.

I don't get any errors when I start WAMP, but my phpinfo() doesn't show Mongo listed, and when I try to something simple like

$m = new Mongo(); // connect

I get this error:

( ! ) Fatal error: Class 'Mongo' not found in C:\development\uswom\btf\test\mongo.php on line 3

My phpinfo shows this information:

Build Date  Aug 23 2011 11:47:20
Compiler    MSVC9 (Visual C++ 2008)
Architecture    x86 
PHP API     20090626
PHP Extension   20090626
Zend Extension  220090626
Zend Extension Build    API220090626,TS,VC9
PHP Extension Build     API20090626,TS,VC9 

When I do php -i from the command line, it shows me that mongo is loaded:

mongo

MongoDB Support => enabled
Version => 1.2.7-

Directive => Local Value => Master Value
mongo.allow_empty_keys => 0 => 0
mongo.allow_persistent => 1 => 1
mongo.auto_reconnect => 1 => 1
mongo.chunk_size => 262144 => 262144
mongo.cmd => $ => $
mongo.default_host => localhost => localhost
mongo.default_port => 27017 => 27017
mongo.long_as_object => 0 => 0
mongo.native_long => 0 => 0
mongo.no_id => 0 => 0
mongo.utf8 => 1 => 1

WAMP is the only php that I have installed, and to make sure that my CLI PHP was matching up with my WAMP phpinfo, I checked the details and they match up:

Build Date => Aug 23 2011 11:47:20
Compiler => MSVC9 (Visual C++ 2008)
Architecture => x86
PHP API => 20090626
PHP Extension => 20090626
Zend Extension => 220090626
Zend Extension Build => API220090626,TS,VC9
PHP Extension Build => API20090626,TS,VC9

Finally, "where php" shows me that command line is running the PHP from my WAMP install: C:\Program Files (x86)\wamp\bin\php\php5.3.8\php.exe

1) Any idea why CLI "php -i" would show that Mongo is loaded, but phpinfo() doesn't?

2) I'm guessing that my "new Mongo()" call is failing for the same reason that phpinfo() isn't showing me that Mongo is loaded, but I'm not sure where to start debugging the Mongo loading issue. I checked wamp/logs/apache_error.log and it shows no errors at startup.

Thanks in advance.

Was it helpful?

Solution

Your question is not clear : can you see that mongo extension on phpinfo() page ?

If not then know that, often, CLI does not use the same php.ini than Apache (phpinfo()).

Look for the proper php.ini to edit, usually named php-cli.ini. Chances are that it is in the same folder than php.ini. Sometimes, it is even located in c:\Windows, so look carefully.

Use "parsed php ini files" in the phpinfo() page, this will get you right to the correct file to edit.

Also, please confirm that you have only one version of PHP installed, because WAMP can handle many PHP engines per instance.

hope this helps!

update : and, as a reminder, restart Apache service at each configuration change

OTHER TIPS

I had a similar problem with WAMP and the Mongo php extension.

I noticed in my Apache error log that it was finding the mongo .dll in /ext, but was choking. After some troubleshooting I realized I had the 64 bit version of WAMP but the mongo php .dll is only distributed from Github as a 32 bit.

So I reinstalled WAMP using the 32 bit distro instead of the 64 bit (I suppose I could have also built the mongo extension as a 64 bit .dll).

Then, I installed the thread safe version of mongo php and it loaded into my phpInfo summary and now I can access the functions, that solved it for me.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top