Ubuntu 14.04 installation of mongodb and PHP mongodb driver



Mongodb is a very famous NoSQL database. The following is the installation of mongodb under Ubuntu 14.04, as well as the configuration for PHP (driver installation, etc.), which is applicable to homestead.

Install mongodb

1. add source

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
sudo apt-get update

2. Start installation

Please refer to here for customized installation packages.

sudo apt-get install -qq mongodb-org

Check whether it is on after installation:

$ ps -ef | grep mongo
mongodb  15683    1  1 03:00 ?        00:00:37 /usr/bin/mongod –config /etc/mongod.conf

Check version:

$ mongo --version
MongoDB shell version: 2.6.6
$ mongo
> db.test.save( { test: 100 } )
> db.test.find()
{ "_id" : ObjectId("549253f4d91767276c02fc14"), "test" : 100 }

Path information and default parameter description:

Sources: /usr/bin/
Logs: /var/log/mongodb/mongod.log
Data: /var/lib/mongodb/
Default ip:
Default port MongoDB is listening: 27017

The above information can be modified by editing / etc / mongod.conf.

On / off

$ sudo service mongod start
$ sudo service mongod stop
$ sudo service mongod restart

Install PHP mongodb driver

1. Install driver

echo "no" > answers.txt
sudo pecl install mongo < answers.txt
rm answers.txt

2. Enable PHP extension

echo 'extension=mongo.so' | sudo tee /etc/php5/mods-available/mongo.ini
sudo ln -s /etc/php5/mods-available/mongo.ini /etc/php5/fpm/conf.d/mongo.ini
sudo ln -s /etc/php5/mods-available/mongo.ini /etc/php5/cli/conf.d/mongo.ini

Restart the server

sudo service php5-fpm restart

Verify installation succeeded

$ php -i | grep 'Mongo'
MongoDB Support => enabled
:sparkles: :sparkles: :sparkles:

Thank you for reading, hope to help you, thank you for your support!