Install mongo db step in centos/fedora
first check your os (32/64)
uname -m
Create a /etc/yum.repos.d/10gen.rep
open file and add bellow line in file and save the file (64bit os)
[10gen]
name=10gen Repository
baseurl=http://downloads-distro.mongodb.org/repo/redhat/os/x86_64
gpgcheck=0
enabled=1
open file and add bellow line in file and save the file (62bit os)
[10gen]
name=10gen Repository
baseurl=http://downloads-distro.mongodb.org/repo/redhat/os/i686
gpgcheck=0
enabled=1
~]# yum install mongo-10gen mongo-10gen-server
~]# service mongo db start
~]# chkconfig --levels 235 mongod on
// step for install php mongo drive
~]# yum install php-devel git httpd
~]# export PHP_AUTOCONF=/usr/bin/autoconf
~]# export PHP_AUTOHEADER=/usr/bin/autoheader
~]# wget http://pecl.php.net/get/mongo-1.0.9.tgz
~]# tar -xzf mongo-1.0.9.tgz
~]# cd mongo-1.0.9
~]# phpize
~]# ./configure
~]# make install
~]# cd /etc/php.d
~]# vi mongo.ini
add bellow line in mongo.ini
extension=mongo.so
~]# service httpd restart
//test mongo db in prompt
//strat mongo
~]# mongo
//databse test use
>use test;
>doc = {"hello": "world", "php": "is alive!" };
>db.phptest.save(doc);
>db.phptest.findOne();
Example in php
<?php
$connection = new Mongo();
$db = $connection->test;
$collection = $db->phptest;
$obj = $collection->findOne();
echo "Hello " . $obj["hello"] . "!";
echo "Show result as an array:";
echo "<pre>";
print_r($obj);
echo "</pre>";
echo "Show result as JSON:";
echo "<pre>";
?>
install rockmongo for web view
download from rockmongo.com/downloads
extract file in web directory
create virtualhost
first check your os (32/64)
uname -m
Create a /etc/yum.repos.d/10gen.rep
open file and add bellow line in file and save the file (64bit os)
[10gen]
name=10gen Repository
baseurl=http://downloads-distro.mongodb.org/repo/redhat/os/x86_64
gpgcheck=0
enabled=1
open file and add bellow line in file and save the file (62bit os)
[10gen]
name=10gen Repository
baseurl=http://downloads-distro.mongodb.org/repo/redhat/os/i686
gpgcheck=0
enabled=1
~]# yum install mongo-10gen mongo-10gen-server
~]# service mongo db start
~]# chkconfig --levels 235 mongod on
// step for install php mongo drive
~]# yum install php-devel git httpd
~]# export PHP_AUTOCONF=/usr/bin/autoconf
~]# export PHP_AUTOHEADER=/usr/bin/autoheader
~]# wget http://pecl.php.net/get/mongo-1.0.9.tgz
~]# tar -xzf mongo-1.0.9.tgz
~]# cd mongo-1.0.9
~]# phpize
~]# ./configure
~]# make install
~]# cd /etc/php.d
~]# vi mongo.ini
add bellow line in mongo.ini
extension=mongo.so
~]# service httpd restart
//test mongo db in prompt
//strat mongo
~]# mongo
//databse test use
>use test;
>doc = {"hello": "world", "php": "is alive!" };
>db.phptest.save(doc);
>db.phptest.findOne();
Example in php
<?php
$connection = new Mongo();
$db = $connection->test;
$collection = $db->phptest;
$obj = $collection->findOne();
echo "Hello " . $obj["hello"] . "!";
echo "Show result as an array:";
echo "<pre>";
print_r($obj);
echo "</pre>";
echo "Show result as JSON:";
echo "<pre>";
echo json_encode($obj);echo "</pre>";
?>
install rockmongo for web view
download from rockmongo.com/downloads
extract file in web directory
create virtualhost
No comments:
Post a Comment