How connect LAMP droplet with MongoDB droplet

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?

Thanks Wouter


Submit an answer
You can type!ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

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.