Step 1: Import the public key used by the package management system.
The Ubuntu package management tools (i.e. dpkg and apt) ensure package consistency and authenticity by requiring that distributors sign packages with GPG keys.
sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv EA312927
Step 2: Create a list file for MongoDB.
Create the /etc/apt/sources.list.d/mongodb-org-3.2.list list file using the command appropriate for your version of Ubuntu:
Ubuntu 12.04
echo "deb http://repo.mongodb.org/apt/ubuntu precise/mongodb-org/3.2 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-3.2.list
Ubuntu 14.04
echo "deb http://repo.mongodb.org/apt/ubuntu trusty/mongodb-org/3.2 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-3.2.list
Step 3: Reload local package database.
Issue the following command to reload the local package database:
sudo apt-get update
Step 4: Install the MongoDB packages.
You can install either the latest stable version of MongoDB or a specific version of MongoDB.
Install the latest stable version of MongoDB.
Issue the following command:
sudo apt-get install -y mongodb-org
Step 5: Install PHP5
This is simple PHP5 installation on our system. You may also need to install other php modules as per your application requirements like php5-xml, php5-mbstring, php5-gettext etc.
sudo apt-get install php-pear php5-dev
Step 6: Install MongoDB PHP Module
Finally we need to Install Mongo PECL extension and add in php configuration file. which provides connectivity between PHP and MongoDB.
sudo pecl install mongo
Note: type no
What makes Ubuntu 12.04 a little different from other systems in how PHP extensions get loading when Apache/PHP starts. To make sure this extension gets loaded, we'll need to add a .ini file to "/etc/php5/conf.d". To do that, run the following command:
sudo vi /etc/php5/apache2/conf.d/mongo.ini
After creating the file, add this line of content:
extension=mongo.so
Also
sudo vi /etc/php5/apache2/php.ini
add this line of content:
extension=mongo.so
After installing the extension, lets restart apache service
sudo service apache2 restart
Step 7: Verify Setup
At this stage we have complete all installation. But make sure that we have properly integrated MongoDB with PHP5. To test this create an phpinfo.php file using following value.
<?php
phpinfo();
?>
phpinfo();
?>