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:

name=MongoDB Repository

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 If you want to change that you have to edit the bind_ip option:


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
Questions? Try the support group

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/

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

And finally restart httpd:

# service httpd restart



You might also like

Install MongoDB in Ubuntu 12.04 with PHP driver
Install MongoDB:sudo apt-key adv --keyserver hkp:// --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

This site uses Akismet to reduce spam. Learn how your comment data is processed.