First, using Yum to install MongoDB
1. Configure the Yum source
Add 10gen.repo files to the/etc/yum.repos.d/directory
Vi/etc/yum.repos.d/10gen.repo
[10gen]
Name=10gen Repository
Baseurl=http://downloads-distro.mongodb.org/repo/redhat/os/x86_64
gpgcheck=0
2. Installing MongoDB server side and client tools
Yum Install Mongo-10gen-server
Yum Install Mongo-10gen
3. Start MongoDB
Service Mongod Start
Set boot up
Chkconfig Mongod on
4. configuration file path/etc/mongod.conf
Test: Enter MONGO at the command line
#查看数据库列表
Show DBS
#切换/CREATE DATABASE (the current database is automatically created when a collection (table) is created)
Use admin;
#当前db版本
Db.version ();
#删除当前使用数据库
Db.dropdatabase ();
#简单插入数据
Db.user.insert ({"Name": "Ceshi", "Age": "18"})
#查询数据
Db.user.find ()
Second, configure PHP MongoDB extension
1. Download MongoDB extension source
wget http://pecl.php.net/get/mongo-1.2.2.tgz
2. Unzip, compile, install
Tar zxf mongo-1.2.2.tgz
CD mongo-1.2.2
Phpize
./configure
Make && make install
Results:
Build complete.
Don ' t forget to run ' make test '.
Installing Shared extensions:/usr/local/php/lib/php/extensions/no-debug-non-zts-20060613/
Indicates success, adding a line to the php.ini file
Extension=mongo.so
Restart the server. PHP-FPM.
3. Testing
See if there is a MONGO extension.
<?php
Phpinfo ();
?>
Code testing,
<?php
$mongo = new MONGO ();
TODO: Database list
$dbs = $mongo->listdbs ();
Print_r ($dbs);
?>
Reference:
1. MongoDB Installation
Http://www.cnblogs.com/shanyou/archive/2012/07/14/2591838.html
2. PHP MongoDB Extension Installation
Http://www.linuxidc.com/Linux/2012-02/53833p2.htm
Installing MongoDB under Centos, and Configuring the PHP MongoDB Database extension