Sunday 6 September 2015

Configuring MongoDB and PHP on Windows

If you are reading then probably you are a beginner. This post will guide you from the basic of how to configure MongoDB and PHP on Windows.

Personally I love MongoDB because of its features and good documentation which makes it easy to learn.

The First Step:

Install MongoDB on your Windows version.
To learn how to install MongoDB visit my earlier post or click on the link below:
Setting Up MongoDB on Windows


The Second Step:

The simplest way to work with PHP on Windows is to use WAMP.

WAMP stands for:
W - Windows
A - Apache Server
M - MySQL
P - PHP

You can download WAMP from Here!

Wow that was easy!

The Third Step:

Now this step can be easy or frustrating. It depends on your luck. I had a hard time figuring out the correct driver for My PHP version.

I can make it simple for you if you have downloaded the exact same as I am specifying below:

1. MongoDB 32 bit
2. WAMP 2.5 (32 Bits & PHP 5.5)

In this case:
  1.  Go to this Link to download the PHP-Mongo Driver.
  2.  Download 'php_mongo-1.5.1.zip'.
  3.  Extract the above file.
  4.  Select 'php_mongo-1.5.1-5.5-vc11.dll' and rename it to 'php_mongo.dll'.
  5.  Paste it in the ext directory 'wamp\bin\php\php5.5.12\ext'.
  6.  Modify the php.ini file - Add 'extension=php_mongo.dll' in php.ini file.

Elaborating on the point 6 i.e modifying php.ini file, it can be done in two ways:

      1. After installing WAMP run the wamp executable(.exe).
      2. You will see a small 'W' icon on the right bottom corner of your screen(i.e. the notifications
           area) as shown in the image.


       3. The second way is to directly search for the 'php.ini' file in the  
           'C:\wamp\bin\php\php5.5.12\' directory and edit it.

For those who haven't downloaded the exact same version files, all the steps are same except Step 2 i.e 'Download 'php_mongo-1.5.1.zip'. At this step you need to download the driver suitable to your php version and then extract it and rename the correct file to php_mongo.dll.

Now restart WAMP by clicking on Restart All Services and then click on Put Online to start the server.

You can check whether PHP has accepted the mongoDB driver(i.e. they are compatible) by opening the browser and typing 'localhost'

 

 Then click on phpinfo().

If mongoDB has been accepted by PHP then on scrollingd down you will find a section describing the mongo_php driver specifications.

Thats it! Your MongoDB and PHP is all set to work together.

Happy Coding! :D






1 comment: