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.
<?php 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.
What is next?
An extension to this article is available at “Connecting and authenticating to MongoDB database from PHP using MongoClient”
I am George Mathew, working as software architect and Android app developer at wptrafficanalyzer.in
You can hire me on hourly basis or on project basis for Android applications development.
For hiring me, please mail your requirements to firstname.lastname@example.org.
My other blogs