How to install up MongoDB and PHP on Ubuntu

Use this tutorial to install MongoDB on Ubuntu.In this tutorial I will explain you How to install up MongoDB and PHP on Ubuntu. Getting a MongoDB server setup and working with PHP is very simple.

Just follow these step:

if you have already installed mongoDB and its not working uninstall completely from your system run this command

sudo apt-get remove mongodb* --purge

Installing MongoDB

Run the following command to import the MongoDB public GPG Key:

sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 7F0CEB10

Now create a file /etc/apt/sources.list.d/10gen.list and include the following line to add the 10gen repository:

echo 'deb http://downloads-distro.mongodb.org/repo/ubuntu-upstart dist 10gen' | sudo tee /etc/apt/sources.list.d/mongodb.list

Now run this command

sudo apt-get update

Now you need to install the MongoDB package. Run this command to install the package

sudo apt-get install mongodb-10gen

You are done now.

Before you can use Mongo in PHP you will need to install the MongoDB driver. FIrst you need to setup the PECL. Run the following command

sudo apt-get install php5-dev php5-cli php-pear

Now you have to Install the MongoDB driver. Run the following command to install the driver.

sudo pecl install mongo

Now we just need to enable the module.
Edit your php.ini file and add the line. Run this command

gksudo gedit /etc/php5/apache2/php.ini

once the file get opened save this line in the file

extension=mongo.so

Save your script and restart your webserver. You should now be able to use MongoDB with PHP.

Hope this tutorial How to install up MongoDB and PHP on Ubuntu help you.