Installing and configuring php mongo driver with Apache in Ubuntu 12.04 LTS

December 23, 2012

In this article, we will see how to install and configure php-mongo driver to use with Apache2 in Ubuntu 12.04 LTS.

Setting up php5 with Apache2 is discussed in the article titled “Setting up php with Apache2 in Ubuntu 12.04 LTS in command mode“.

1. Installing PHP PEAR package

PEAR is a package manager for PHP, like apt and yum in Ubuntu and Fedora respectively. We can install pear package in Ubuntu 12.04 with the given below command.

$sudo apt-get install php-pear

2. Installing PHP-Mongo driver that connects PHP and MongoDB

$sudo pecl install mongo

3. Configuring PHP-Mongo driver in Apache2

Open the file “/etc/php5/apache2/php.ini” and add the given below line

4. Restart Apache2 Server in Ubuntu 12.04

$sudo service apache2 restart

5. Checking PHP-Mongo driver module in phpinfo()

Create a file namely “index.php” in the document root with the given below code.

    echo phpinfo();

Now enter the URL of file “index.php” in a web browser. Then a page containing available list of PHP modules will be shown. If the installation is success, we can locate the “mongo” module in the list. The mongo module will be listed as shown in the Figure 1.

Listing mongo module in the output of phpinfo()

Listing mongo module in the output of phpinfo()


What is next?

An extension to this article is available at “Connecting and authenticating to MongoDB database from PHP using MongoClient

How to hire me?

I am George Mathew, working as software architect and Android app developer at

You can hire me on hourly basis or on project basis for Android applications development.

For hiring me, please mail your requirements to

My other blogs

Android Knowledge Quiz

Ready to test your knowledge in Android? Take this quiz :

Tags: , , ,

Leave a Reply

Your email address will not be published. Required fields are marked *

Be friend at g+

Subscribe for Lastest Updates

FBFPowered by ®Google Feedburner