Installing MongoDB under Centos, and Configuring the PHP MongoDB Database extension

Source: Internet
Author: User
Tags install mongodb mongodb server php mongodb

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.