Installing the PHP5 MongoDB Driver (mongo.so) on Ubuntu 12.04

December 18th 2012

Setting up the Mongo Driver for PHP is apparently something that's causing quite a few people some grief.

To setup the Mongo extension (mongo.so) for PHP, first log into your box via SSH and issue the following commands (these work for the default Ubuntu 12.04 installation)

Text Snippet:
sudo su
apt-get install php5-dev make
pecl install mongo

After these are installed, you'll need to edit the php.ini file.

Text Snippet:
nano /etc/php5/apache2/php.ini

Find the section that contains extensions. You can do this by pressing ctrl+w and searching for 'extension='

In this section add:

Text Snippet:
extension=mongo.so

If you also want to use the driver in CLI, then also edit the php.ini for CLI.

Text Snippet:
nano /etc/php5/cli/php.ini

Again, you'll want to add the extension, so search for it and add this line again:

Text Snippet:
extension=mongo.so

After that you'll want to restart your webserver (presumably Apache 2)

Text Snippet:
/etc/init.d/apache2 restart

You should now have the PHP Mongo classes available and be able to use Mongo from within your application.