Ubuntu 14.04 Installation MongoDB and PHP MongoDB Driver details
- 2020-06-07 05:30:23
- OfStack
instructions
MongoDB is a very famous NOSQL database. Below is the installation of MongoDB under Ubuntu 14.04, as well as the configuration for PHP (driver installation, etc.). This method works for Homestead.
Install MongoDB
1. Add the 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 the installation
You can customize the Package installation here.
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 parameters:
Sources: /usr/bin/
Logs: /var/log/mongodb/mongod.log
Data: /var/lib/mongodb/
Default ip: 127.0.0.1
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. Open the 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 that the installation is successful
$ php -i | grep 'Mongo'
MongoDB Support => enabled
:sparkles: :sparkles: :sparkles:
Thank you for reading, I hope to help you, thank you for your support to this site!