MongoDB installation basic tutorial under LInux

  
 

Install and configure mongodb under linux Step 1: Download the file
For 32-bit linux$ curl http://downloads.mongodb.org/linux/mongodb-linux-i686-1.4.4.tgz > mongo .tgz$ tar xzf mongo.tgz for 64-bit linux$ curl http://downloads.mongodb.org/linux/mongodb-linux-x86_64-1.4.4.tgz > mongo.tgz$ tar xzf mongo.tgz

If you do not install curl First install apt-get install curl Step 2: Create a data folder By default, MongoDB will store data in /data/db/folder, this folder needs to be created manually. Created by:
$ adduser mongodb$ passwd mongodb$ sudo mkdir -p /data/db/$ sudo chown `id -u` /data/db$ chown -R mongodb:mongodb /data

Of course Specify the MongoDB to store data in a separate directory with the --dbpath command. Step 3: Let the database run in the console:
$ nohup ./mongodb-xxxxxxx/bin/mongod &$ ./mongodb-xxxxxxx/bin/mongo> db.foo.save( { a : 1 } ) > db.foo.find() or ./mongodb-linux-x86_64-1.4.4/bin/mongod

Add vim /etc/rc.local to the boot entry and add the following code to save:

#add mongonDB service/usr/local/webserver/mongodb/bin/mongod –dbpath /data/db –logpath /data/mongodb_log/mongodb.log –logappend –rest &

Note: Use mongo as a system command to make it available in any directory:
cp /usr/local/webserver/mongodb/bin/mongo /usr/bin/

Install MongoDB PHP
Extensions to download PHP extensions according to your own PHP version: http://github.com/mongodb/mongo-php-driver/downloads, tips: 1. VC6 is suitable for Apache and VC9 for IIS; 2. Thread safe is suitable for PHP to run with modules. The way, Non-thread safe is suitable for CGI operation. Modify php.ini, add: extension=php_mongo.dll, restart the web server.

Test with PHP program, success!
$conn = new Mongo("192.168.12.129:27017");$db = $conn->selectDB("test");//$db = $conn->test;$collection = $db->shicai;$rows = $collection->find();print_r($rows); exit;



Copyright © Windows knowledge All Rights Reserved