How connect LAMP droplet with MongoDB droplet

September 7, 2015 1.1k views
MongoDB LAMP Stack DigitalOcean NoSQL PHP Ubuntu

Hi, I created a droplet with Ubuntu 14.04 x64 and LAMP where I uploaded a codeigniter framework with working scripts. This works fine because I receive a Codeigniter error.

I also created a droplet with Ubuntu MongoDB 3.0.5 on 14.04.

Now what I want is to connect the Codeigniter framework with that MongoDB. How can I do this? My codeigniter frameworks works local with a local MongoDB so I tried to change the config file of my MongoDB lib but still receive 'Unable to connect to your database server using the provided settings.'

These are the details from the Codeigniter file:
(I removed confidential information).

// Generally localhost
$config['host'] = "[THE IP OF THE MONGODB DROPLET]";
// Generally 27017
$config['port'] = 27017;
// The database you want to work on
$config['db'] = "[A DATABASE NAME]";
// Required if Mongo is running in auth mode
$config['user'] = "root";
$config['pass'] = "[PASSWORD FOR THE ROOT USER]";

Any idea?


1 Answer

By default, the MongoDB One-Click App is configured with MongoDB bound to localhost, so that it is only accessible locally. For all the details, see:

In order to make it accessible externally, modify the value of bind_ip in /etc/mongod.conf Setting up a firewall so that only your LAMP Droplet can access the MongoDB Droplet is also a good idea. Using UFW on your MongoDB instance, you would run:

sudo ufw default deny incoming
sudo ufw default allow outgoing
sudo ufw allow ssh
sudo ufw allow from lamp.droplet.ip.addr
sudo ufw enable

You should make sure to review the security checklist from the MongoDB documentation before making your database accessible externally as well.

MongoDB is a highly-scalable NoSQL database with a document-based data model and an expressive query language. DigitalOcean's MongoDB One-Click application allows you to quickly spin up a droplet with MongoDB pre-installed. It aims to help get your application off the ground quickly.
Have another answer? Share your knowledge.