William Jiang

JavaScript,PHP,Node,Perl,LAMP Web Developer – http://williamjxj.com; https://github.com/williamjxj?tab=repositories

CentOS 6.2: Install mongoDB server and PHP mongo extension

CentOS 6.2: Install mongoDB server and PHP mongo extension

Here I summary the steps of installing mongoDB server and PHP mongo extension which are working on CentOS 6.2.

A. Install mongoDB server

To install mongoDB server, a good reference is here. My steps are:
(1) Following the instruction, use ‘yum’ to do the installation.
$ sudo vi /etc/yum.repos.d/10gen.repo

name=10gen Repository

(2) $ yum install mongo-10gen mongo-10gen-server to install mongoDB server.

(3) The configure is reside on /etc/mongod.conf, and the start/stop/restart script is /etc/rc.d/init.d/mongod. To start the service:
$ sudo service mongod start, or:
$ sudo /etc/init.d/mongod restart

Make sure the daemon works properly: $ sudo chkconfig mongod on

(4) It is running now. This MongoDB instance will store its data files in the /var/lib/mongo and its log files in /var/log/mongo, and run using the mongod user account.
Next step we are going to install PHP mongo extension in case to access the server.

B. Install and configure PHP mongo extension

(1) Using pecl(http://pecl.php.net/) is a simpler and effective way, instead of others such as wget & configure, or yum.Basically pecl does the following things: wget, phpize, ./configure, make && make test && make install.
$ sudo pecl install mongo
The mongo extension is now installed.

(2) Now add mongo.so to php.ini as a PHP extension.
$ sudo vi /etc/php.ini:


(3) Restart http server to make the change is active.
$ sudo service httpd restart

(4) Write a test script to make sure the installation and configure are right. (or using phpinfo to check).
vi test_mongo.php:

$m = new Mongo();
and return:
Mongo Object
    [connected] => 1
    [status] => 
    [server:protected] => 
    [persistent:protected] => 

Now a new mongo cache system is ready to use.


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: