Wordpress (PHP & MYSQL) + Node JS & MongoDB in one droplet

April 16, 2015 5.5k views
MongoDB Node.js PHP WordPress

Hi there,

I am looking to host a my SaaS service in digitalocean's droplet. The main system will be done in JS with MongoDB as the database. However I would like a "blog" page which runs on wordpress (PHP & MYSQL). My question is, " Is it possible to host 2 of these architecture in one droplet?" Or it requires 2 droplet to run 2 different environment?

  • you should be able to run two in one droplet. I am doing that with a FAMP stack for Zabbix as well as a node.js mongodb for a project I am working on. It depends on the resources you have allocated. I have the smallest size running zabbix + mongodb but I wouldn't advise that for production. :) I should add that I am using FreeBSD droplets, but the concept is the same. In the "old" days we used to try to cram as much as we could on one box because there were no "clouds" as we know them today nor were machines cheap.

    I would however suggest breaking apart your DB and front end webserver. Also with MongoDB you might want to take advantage of it's fantastic replication capabilities. That would require more than one droplet.

  • I just noticed Ryan answered this with way more detail than I did. Nginx proxy is the way to go for sure. Alternatively you could try haproxy or in my case I am using varnish and nginx. Thanks Ryan I didn't notice your reply before I started blabbering away.

1 Answer

This should be possible. Here is what I would recommend.

1.) Configure a LEMP stack (nginx instead of Apache as the web server) or use the LEMP one-click image to start.

2.) Install and configure node and MongoDB as you normally would.

3.) Assuming that you will be using separate domain or subdomain names for your node and wordpress sites you will want to create a second server block in your nginx configuration file /etc/nginx/sites-enabled/default that will redirect the traffic for your second site to the node server.

First add a server_name variable to your existing server block (if you have not already) which has the domain/subdomain name used for your Wordpress site.

Then add your second server block:

server {
        listen 80 default_server;
        listen [::]:80 default_server ipv6only=on;


location / {
    proxy_pass       http://localhost:8000;
    proxy_set_header Host      $host;
    proxy_set_header X-Real-IP $remote_addr;


Make sure to set the servername variable to your domain/subdomain and the port in the proxypass variable to the port that node is listening on.

Now when a user visits your droplet via either domain/subdomain the request is processed by nginx. If the request is for it will go to your wordpress site. If the request is instead or it would be proxied to your node server.

If you want these to live on the same domain instead of two separate ones you would just want to add a second location block to the configuration for your wordpress site like the one shown below:

location /node/ {
    proxy_pass       http://localhost:8000;
    proxy_set_header Host      $host;
    proxy_set_header X-Real-IP $remote_addr;

With this configuration, requests for and any directories under it would go to wordpress unless the request is under Anything in that path would be routed to your node service.

by Justin Ellingwood
A LEMP stack (Linux, Nginx, MySQL, and PHP) is a powerful set of software that can be configured to serve dynamic sites and web apps from your server. In this guide, we will discuss how to install a LEMP stack on an Ubuntu 14.04 server.
Have another answer? Share your knowledge.