This time i’ll explain how to install Mongo DB on Windows Environment, Mongo DB can be installed on several OS those are Linux, Mac, and Windows. Since i’m using Wamp Server as multi packages for Apache, PHP, and MYSQL, i’ll also explain an example to add Mongo DB as PHP Extension and the simplest way to run Mongo DB service on Windows.
Prerequisite : Wamp Server is already installed on your Windows (Version wampserver2.5-Apache-2.4.9-Mysql-5.6.17-php5.5.12-32b)
Installation :
Now, Lets get the ball rolling :
1st. First, we have to download the latest build Mongo DB on MongoDB Official, download the zip file for version Windows 64-bit 2008 R2+ legacy(Version 3.0.1).
2nd. After the file has been downloaded, we have to create some directories.
- create the Mongo DB base directory under C:\wamp\bin and named as “mongodb”.
- create the Mongo DB version directory under C:\wamp\bin\mongodb and named as “mongodb-win32-x86_64-2008plus-3.0.1”.
- create the following directories under C:\wamp\bin\mongodb\mongodb-win32-x86_64-2008plus-3.0.1
3th. Create the file “mongodb.conf” under C:\wamp\bin\mongodb\mongodb-win32-x86_64-2008plus-3.0.1\conf, then add this configuration.
1 2 3 4 5 6 7 8 9 10 11 12 13 |
# mongodb.conf # data directory dbpath=C:\wamp\bin\mongodb\mongodb-win32-x86_64-2008plus-3.0.1\data\db # log directory logpath=C:\wamp\bin\mongodb\mongodb-win32-x86_64-2008plus-3.0.1\logs\mongodb.log logappend=true # run on localhost for development bind_ip = 127.0.0.1 # using port port = 27017 |
4th. Extract the downloaded file into bin folder.
5th. Open the windows command prompt as administrator privilege and locate it to C:\wamp\bin\mongodb\mongodb-win32-x86_64-2008plus-3.0.1\bin.
6th. Execute this command to install Mongo DB as a windows service.
1 |
mongod.exe --install --config C:\wamp\bin\mongodb\mongodb-win32-x86_64-2008plus-3.0.1\conf\mongodb.conf --logpath C:\wamp\bin\mongodb\mongodb-win32-x86_64-2008plus-3.0.1\logs\mongodb.log |
7th. Open “services.msc” and run MongoDB service then start the service. We can set manually or automatically when windows start up.
Add Path on Windows Environment Variables :
1st. Right click on My Computer.
2nd. Click Advanced system settings.
3th. Click Environment Variables button.
4th. Click PATH on Variable column, then append this path.
1 |
;C:\wamp\bin\mongodb\mongodb-win32-x86_64-2008plus-3.0.1\bin;C:\wamp\bin\php\php5.5.12 |
note : adjust the version and take a look the delimiter “;”.
Check everything is running well :
1st. Open the windows command prompt as administrator privilege.
2nd. check with this command :
1 2 3 4 5 6 7 8 9 10 |
c:\> mongo MongoDB shell version: 3.0.1 connecting to: test > > use test; switched to db test > db.test.insert( {"hello":"fatkhan fauzi"} ); > db.test.find(); { "_id" : ObjectId("551f2cc08c89bea488082564"), "hello" : "fatkhan fauzi" } > exit; |
Add Mongo DB PHP Extension into WAMP Server PHP :
1st. Download the latest driver for windows environment from Amazonaws.
2nd. Choose the file that appropriate with the environment, i have used “php_mongo-1.6.6-5.5-vc11-x86_64.dll”, then copy this file into this directory C:\wamp\bin\php\php5.5.12\ext and rename it to “php_mongo.dll”.
3th. Add this line “extension=php_mongo.dll” on the “php.ini” file in this directory C:\wamp\bin\apache\apache2.4.9\bin\php.ini.
4th. Restart all Wamp Services.
5th. Check the extension is work by clicking Wamp icon -> PHP -> PHP Extensions, and ensure the php_mongo is checked.
Finally, congratulation the Mongo DB service has been installed and Mongo DB PHP extension has been added. 🙂
A passionate software engineer who wants to share anything that he learns and some of his life experiences. Want to know more about him? see Fatkhan Fauzi Profile
hi, i have already made all the step you have explained. now when i try to call a php file that use mongodb db i have an error 500
hm.. sorry i have never found the same case..
Thanks man. It worked.
thanks too.
glad to hear that.
Thank you very much !
You’re welcome Marco..
Glad to help.. 🙂
dbpath=C:\wamp\bin\mongodb\mongodb-win32-x86_64-2008plus-3.0.1\data\db
I don’t see it mentioned that you need a “db” folder in the “data” folder, but if it’s not there, MongoDB won’t start.
Thanks John, maybe i’ve missed that one.. 🙂
Kehebatan macam apa lagi ini yang ditunjukkan oleh Kisanak
ampun juragan.. baru installasi.. 😀