Install MongoDB and the PHP driver in CentOS

Install MongoDB server

Eneko
enekochan
1 min readJan 10, 2016

--

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

Then install mongodb with this commando:

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:

To start the server run this command:

To stop the server run this command:

If you want the server to start on boot:

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

Install the PHP driver

Install the required dependencies and the mongo PHP driver itself:

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:

And finally restart httpd:

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

--

--