How to install Mongo db on php

In this tutorial I’m going to show you how you can install the  Mongo DB extension on php. But first, let me give you a simple introduction on what Mongo DB is. Mongo DB is a NO SQL database, which means Not Only Standard Query Language. Here’s a list of NO SQL databases:

http://nosql-database.org/

So what’s the advantage of Mongo DB over MySQL or other databases which uses SQL? Here’s the introduction of Mongo DB:

http://www.mongodb.org/display/DOCS/Introduction

And here’s a summary in case you’re feeling lazy today:

  • Document-oriented
  • High Performance
  • High availability
  • Easy Scalability
  • Rich query Language

Well, I’m not that expert at explaining things. And the main purpose of this article is to show you how to install Mongo DB, so I guess a simple outline will do. And yeah, you’re lazy today so you won’t really be reading this part and have gone ahead with the installation.

 

Requirements

 

Installation

First, you’ll have to go to the download page of the Mongo DB. And you’ll see a highly confusing table, you’ll really have to examine it carefully in order to download the right one. Basically you’ll want a production release that is for Windows 32-bit operating system. It says Windows 32-bit, but I don’t really know if it works on Windows 95 or the first version of Windows. But if you are on Windows 7 just like me, the it will probably work for you.

image

Next, download the mongo DB extension for php. You can use this link to download the php extension if you didn’t catch the link above. But first, you need to make sure that we have the same php version and compiler. If not then you can use this link, a collection of mongo DB extensions for php 5.3.5. And if you don’t know how to get the information below, just create a new php file and type phpinfo(), save it then access the file on your browser.

image

Next, extract the mongo DB archive file. Then go to the bin folder. What you’ll see is a bunch of executable files, but you only have to execute 2 of them. Here’s the order of execution:

  1. mongod
  2. mongo

You can go ahead and try some commands like:

db.people.save({name: 'ash'});

It’s the equivalent of the insert command in sql.

If you want to verify that it is actually stored in the database, you can try out this command:

db.people.findOne({name: 'ash'});

Yup!, that’s the equivalent of the select statement in sql.

Ok, enough with that. You can go give yourself a jumpstart by taking up the tutorial in the mongo DB site, just click on the big TRY IT OUT LINK to get started.

Next, paste the mongo DB extension to the ext folder in php. The path to my ext folder looks something like the one below. You can make use of it as a basis.

D:wampbinphpphp5.3.5ext

Next, you have to insert this line on the php.ini file. Of course, you don’t paste it on just anywhere else. You have to paste it where the other extensions are

extension=php_mongo.dll

I have placed mine as the first extension on the list, the one’s with the semi-colon at the beginning are disabled. You can also enable and disable existing extensions from the wampserver tray icon. But because the mongo DB extension doesn’t yet exist, we needed to manually place it on the php.ini file:

image

After that, save the changes to you php.ini file and restart all services from the wampserver tray icon.

To test if you can already make use of Mongo DB in php, just create a new php file and paste this line:

$conn = new Mongo();

If you don’t get any error, then All Izz Well as Phunsuk Wangdu said(that’s from the movie called 3 idiots, definitely worth watching, very funny and inspiring).

But if you get any errors, here’s what you need to do:

  • Make sure that mongo.exe and mongod.exe are running, you can go check it out from the Windows Task Manager.
  • Make sure that you have the right mongo DB php extension and that it is enabled.

 

Conclusion
That’s it for this tutorial! Mongo DB is a good My SQL alternative for small php projects. Next time, were going to make a simple CRUD application using php and mongo DB.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s