Install MongoDB and the PHP driver in CentOS

Install MongoDB server

Create the /etc/yum.repos.d/mongodb-org-3.0.repo file with this content:

[mongodb-org-3.0]
name=MongoDB Repository
baseurl=https://repo.mongodb.org/yum/redhat/$releasever/mongodb-org/3.0/x86_64/
gpgcheck=0
enabled=1

Then install mongodb with this commando:

# yum install -y mongodb-org

This are the important files and folders for MongoDB in CentOS:

  • Configuration file: /etc/mongod.conf
  • Data files: /var/lib/mongo/
  • Logs files: /var/log/mongodb/

By default the used port is 27017 and also you can ONLY make connections to it within the localhost or 127.0.0.1. If you want to change that you have to edit the bind_ip option:

bind_ip=127.0.0.1

To start the server run this command:

# service mongod start

To stop the server run this command:

# service mongod stop

If you want the server to start on boot:

# chkconfig mongod on

Once the service is running we can connect to it with the mongo command:

$ mongo
MongoDB shell version: 3.0.6
connecting to: test
Welcome to the MongoDB shell.
For interactive help, type "help".
For more comprehensive documentation, see
	http://docs.mongodb.org/
Questions? Try the support group
	http://groups.google.com/group/mongodb-user
>

Install the PHP driver

Install the required dependencies and the mongo PHP driver itself:

# yum -y install gcc openssl-devel php-devel php-cli php-pear
# pecl install mongo

Note: the library will be installed in /usr/lib64/php/modules/mongo.so

Activate it in /etc/php.ini or in it’s own file in /etc/php.d/30-mongo.ini:

extension=mongo.so

And finally restart httpd:

# service httpd restart

mongodb-logo

Ref: http://docs.mongodb.org/manual/tutorial/install-mongodb-on-red-hat/
http://docs.mongodb.org/ecosystem/drivers/php/

You might also like

Install MongoDB in Ubuntu 12.04 with PHP driver
Install MongoDB:sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 7F0CEB10 echo...

Install and configure MongoDB and PHP driver with MacPorts
Installing and configuring MongoDB with MacPortsInstalling MongoDB with MacPorts is as easy as...

MongoDB: Recover Data after an Unexpected Shutdown in Ubuntu
If you try to run mongod but it fails to start and have this error in the log file (/var/log/mongodb/mongodb.log)...

Shrink MongoDB journal files
Trying to get some space in my harddrive I noticed that the journal files of MongoDB where around 3GB.Fixing...

Leave a Comment