Install MongoDB and the PHP driver in CentOS
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
Ref: http://docs.mongodb.org/manual/tutorial/install-mongodb-on-red-hat/
http://docs.mongodb.org/ecosystem/drivers/php/