ejrado
ejrado

Reputation: 21

Trying to install mongodb in php with MAMP on Windows

I am trying to install mongo in php 5.6.0 using MAMP 3.0.

I have correctly downloaded the mongo library and added it to my php.ini.

extension=php_mongo-1.5.7-5.6-vc11.dll

When I run php from the command line, I receive the following (mongo works):

C:\MAMP\bin\php\php5.6.0>php -c ..\..\..\conf\php5.6.0\php.ini -i | findstr /R /C:"mongo"
mongo
mongo.allow_empty_keys => 0 => 0
mongo.chunk_size => 261120 => 261120
mongo.cmd => $ => $
mongo.default_host => localhost => localhost
mongo.default_port => 27017 => 27017
mongo.is_master_interval => 15 => 15
mongo.long_as_object => 0 => 0
mongo.native_long => 0 => 0
mongo.ping_interval => 5 => 5

However, when I start MAMP with errors_on, I receive the following:

PHP startup: Unable to load dynamic library 'C:\MAMP\bin\php\php5.6.0\ext\php_mongo-1.5.7-5.6-vc11.dll' - %1 is not a valid Win32 application.

What am I doing wrong?

Upvotes: 1

Views: 1211

Answers (3)

Edoardo
Edoardo

Reputation: 87

After struggling a lot with this problem I finally found how to do it:

  1. find on your enviroment the REAL php.ini location used by the system. To do this create a page with phpinfo() and read it on browser, there you find the location of php.ini configuration, in my enviroment was under C:\Windows
  2. open in admin mode the php.ini file and edit it adding, if not exist, the mongo info about extension: i.e. : extension=php_mongodb.dll ensure you type it right (underscore, "mongodb", etc...); than save all.
  3. in the same file look for the extension_dir, the extension directory used by the current php installation. In my enviroment it was C:\MAMP\bin\php\php7.3.19\ext. Now go there and this is the folder where you have to copy past the RIGHT dll
  4. go here https://pecl.php.net/package/mongodb and find the RIGHT version for your enviroment that means you have to know if you are running on x86 or x64 (look on System Info) and if your config usese Thread Safe or not (run on cmd php -i|findstr "Thread"). In my config it was x64 and TS.....NOW this is THE POINT: under that link you will find a lot of versions i.e. 1.12.0 or 1.7.1 and so on, you have to open the sublink and on bottom of page look if the opened one is compatible with your php version (i.e.: 7.3) BUT you have to do anyway some tries with those dll version, in my case I found that the 1.8.0 was compatible with PHP 7.3 I copied it in the ext folder of point 3) BUT nothing worked, so I needed to find a minor version ALWAYS compatible with my PHP 7.3. So for php 7.3 there were at least 3 dll version (1.8, 1.7, 1.6 and so on...) I had success with dll 1.6....SO MAMP needs to find the right one for your system...as soon as I placed the right files in the ext directory and restarted Apache via MAMP interface, the phpinfo spit out the notice that mongo was recognized!!!

So the trick is just try the right dll for PHP version until it match!

Upvotes: 0

ejrado
ejrado

Reputation: 21

I finally resolved this by down-revving php and the mongo driver until I could find one that played well together. I'm using php 5.5.12 with mongo driver php_mongo-1.4.5-5.5-vc11.dll.

I don't think this has anything to do with MAMP per se, it's more about getting apache to play with php and mongo.

Upvotes: 1

René Höhle
René Höhle

Reputation: 27295

Under Windows you have to use the thread safe version. Otherwise the module can't be loaded. You should have a look at the PHP-Version in your case 5.6 of that module and an ts in the filename for your extension.

But i think your problem is that you use a 64bit version. In your package is a file called:

php_mongo-1.5.7-5.6-vc11-x86_64.dll that should work.

https://s3.amazonaws.com/drivers.mongodb.org/php/index.html

Upvotes: 1

Related Questions