MongoDB installation in Ubuntu 14.04

We’ll be seeing how to install MongoDB and get it working with PHP.

If you had followed the step of installing mongo PECL extension you can undo it by doing the following, as this will be provided by the php5-mongo package, including the required changes in the php configuration, which we’ll be installing shortly afterwards.

  • Removing any entry in the php.ini file that you made for mongo extension.
  • Remove the PECL extension by:
sudo pecl uninstall mongo

Now do the following steps to complete the installation:

sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 7F0CEB10
echo "deb http://repo.mongodb.org/apt/ubuntu "$(lsb_release -sc)"/mongodb-org/3.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-3.0.list
sudo apt-get update

sudo apt-get install -y mongodb-org
sudo apt-get install php5-mongo

After this restart your computer, only after that the MongoClient class will be available for use.

References