MongoDB is an open source NoSQL database. These days mongodb is getting more popularity between web developers for their processing speed. And for PHP5 we all are aware that it is use widely use for faster development.
In this article we are installing Latest MongoDB database with PHP5 and Apache2 web server on Ubuntu 14.04 LTS. This article will also work with other Ubuntu versions.
Step 1: Install Apache2
First install Apache2 web server on our system using following command, this is available under default repositories of Ubuntu.
$ sudo apt-get install apache2
After installing Apache2 it will by default start on port 80. You can change default apache2 port in /etc/apache2/ports.conf configuration file.
Step 2: Install MongoDB
First add the public key of repository in our system which is required for checking packages during installation and then add the 10gen apt repository in system with the following commands.
$ sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 7F0CEB10 $ echo 'deb http://downloads-distro.mongodb.org/repo/ubuntu-upstart dist 10gen' | sudo tee /etc/apt/sources.list.d/mongodb.list
Now execute following command to install latest version of MongoDB. It default run on port 27017.
$ sudo apt-get update $ sudo apt-get install mongodb-org mongodb-org-server
Step 3: 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 php5 php5-dev libapache2-mod-php5 apache2-threaded-dev php-pear php5-mongo
Step 4: 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 $ sudo echo "extension=mongo.so" >> /etc/php5/apache2/php.ini
After installing the extension, lets restart apache service
$ sudo service apache2 restart
Step 5: 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(); ?>
Now put this file on servers document root (default is /var/www) and access through web browser.