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
(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).
$m = new Mongo();
[connected] => 1
Now a new mongo cache system is ready to use.