user3844796
user3844796

Reputation: 11

MongoDB Windows configuration

I want to use mongodb with php on my machine using wamp server. I preferably need a step by step installation process.

What I have already tried:
I started the Mongo server using command prompt.
I then downloaded the appropriate PHP driver and added that .dll in the \ext folder, and updated by php.ini file with extension=php_mongo.dll.

Upvotes: 0

Views: 360

Answers (1)

Wolfish
Wolfish

Reputation: 970

We can install mongodb into the c:\wamp directory, create conf,data,log directories, and configure mongod to run as a windows service.

  1. Download the latest win32 build of mongodb, choosing your architecture (32bit or 64bit) from http://www.mongodb.org/downloads.

  2. Create the directory c:\wamp\bin\mongodb\ and extract the contents of the zip archive here. Your directory structure should look something like the following depending on the version number and architecture you download: C:\wamp\bin\mongodb\mongodb-win32-x86_64-2.0.2\

  3. Create the following directories

    mkdir c:\wamp\bin\mongodb\mongodb-win32...2.x.x\data mkdir c:\wamp\bin\mongodb\mongodb-win32...2.x.x\data\db mkdir c:\wamp\bin\mongodb\mongodb-win32...2.x.x\logs mkdir c:\wamp\bin\mongodb\mongodb-win32...2.x.x\conf

  4. Create the file c:\wamp\bin\mongodb\mongodb-win32…2.x.x\conf\mongodb.conf and add the following base configuration.

#

 mongodb.conf

# data lives here
dbpath=C:\wamp\bin\mongodb\mongodb-win32...2.x.x\data\db

# where to log
logpath=C:\wamp\bin\mongodb\mongodb-win32...2.x.x\logs\mongodb.log
logappend=true

# only run on localhost for development
bind_ip = 127.0.0.1                                                             

port = 27017
rest = true
  1. Execute the windows console(command line) as administrator and change to the c:\wamp\bin\mongodb\mongodb-win32…2.x.x\bin directory.

  2. Execute the following command to install mongod as a windows service.

    mongod.exe --install --config c:\wamp\bin\mongodb\mongodb-win32...2.x.x\conf\mongodb.conf --logpath c:\wamp\bin\mongodb\mongodb-win32...2.x.x\logs\mongodb.log

  3. Execute services.msc and scroll down to find the Mongo DB service. Right click on the service and choose start. From here you can choose the have the service started automatically on boot or change it to manual and you will need to start the service each time.

  4. We can confirm that mongod is running by inspecting the log file located at c:\wamp\mongodb\mongodb-win32…2.x.x\logs\mongodb.log

Note: Each time you make changes to mongodb.conf, you will need to restart the Mongo DB service.

Adding mongo.exe to your path

mongo.exe is the MongoDB shell, it will be very convenient to add the bin directory to your PATH environment variable so that you can simple type mongo at the command line regardless of your current working directory.

  1. Right Click on My Computer
  2. Choose Properties and Advanced System Settings
  3. Click the Environment Variables button
  4. Under system variables scroll down and double click on Path.
  5. Append the following to the existing Variable value.

;C:\wamp\bin\mongodb\mongodb-win32-x86_64-2.0.2\bin Note: The ; (semicolon) at the beginning is the delimiter between each path. While you are here, it’s a good idea to also add the path to php.exe.

;C:\wamp\bin\php\php5.3.9 Remember, your version numbers will probably vary slightly so double check the correct path for your machine and revision of wamp.

Use mongo.exe to confirm everything is up and running

Start | Run | cmd.exe

c:\> mongo
MongoDB shell version: 2.0.2
connecting to: test
>
> use test;
switched to db test
> db.test.insert( {"hello":"world"} );
> db.test.find();
{ "_id" : ObjectId("4f33df871c81e6d645a53dd3"), "hello" : "world" }
> exit;

Installing the Mongo PHP Extensions (php_mongo.dll)

  1. Download the latest version of the win32 php extension from https://github.com/mongodb/mongo-php-driver/downloads. For this example I used mongo-1.2.5.zip

  2. Extract the zip archive find the mongo-1.2.5-php5.3vc9ts/ directory. The ts in the folder name means thread safe.

  3. Copy c:\wamp\bin\php\php-5.3.x\ext\

  4. Edit c:\wamp\bin\apache\Apache2.2.xx\bin\php.ini and add the following line near the other loaded extensions.

    extension=php_mongo.dll

  5. Restart all the wamp services by clicking on the wamp task tray icon and choosing ‘Restart All Services’.

  6. Open your browser to http://127.0.0.1/?phpinfo=1 to confirm that the mongo driver is loaded.

Upvotes: 1

Related Questions