How To Run 8 Side-Projects From A Single Server For 12 EUR / mo

H

In this article, I want to share how I manage to run 8 side-projects (mostly written in Rails) from a single server for 12 eur / mo.

First of all, why side-projects? Isn’t all this applicable to webdev in general?

Of cause, it is. At least partially I guess. But things are a bit different when you have a team of 50 devs vs. 5 devs vs. just you.

I’m going to focus on that last extreme case, i.e. how to manage multiple side-projects in a most efficient way when there’s just you with not too much spare time (still have your day job) and limited money to spend (otherwise your wife won’t be happy). So you want to spend this time and money as efficiently as possible.

Version Control

Your side-project will gonna have to be stored somewhere (privately). Even if you are the single developer, you may still want a Git hosting to sync code with the server.

Github is fantastic, but you can only have private repositories on a paid plan ($7 / mo). On the other side, Bitbucket is also very solid and also free for unlimited private projects.

Getting a Server

Before you start, you need a server. There are multiple choices available on the market for getting a VM. For example, Amazon EC2, and Google Cloud Compute. But in my experience, it’s better to not go with behemoth cloud platforms, as they quickly become a money drain. A better option would be to use Digital Ocean, or Linode. The pricing there is much more predictable, and they don’t try to vendor-lock you.

But my favorite provider and this is what I use now is Scaleway. It is very good for value per money. See, you can get a bare-metal server in Amsterdam with 4 cores, 8 Gb of memory for 12 EUR / mo .

the infrastructure

Now that you have a server how do you actually run your projects on it? Configuring the server for each particular project is quite tricky, and supporting / updating stuff is even more time-consuming.

The solution is Docker.

All of my side-projects located on a single Ubuntu server and each of them is running in a docker container. Every container exposes a custom port and I have a globally installed NGinx that dispatches the requests to Docker containers accordingly.

The advantage of this approach is that you can serve multiple projects from one server. For example, I have 8 projects (most of those are in Rails) + the databases. And all of them are running on a single server for 12 eur / mo without interfering with each other. The lightweight Docker containers make it happen.

Now that I look at htop output, it looks as if I only use 4 Gb or RAM out of 8. Which means there’s still a room for more projects.

So let’s say I need to deploy my new project. Here’s what I do.

1. create a dockerfile

What you have in this file is highly dependent on what language your project is written in. In this case, as you can see, it’s a Rails projects with some JavaScript dependencies.

By the way, if you’re into Rails here’s a very good book on Docker.

2. docker-compose file

With docker-compose, you can define your server configuration containing multiple containers. In this case, we have 2. One for the app itself, and the next one is for the database.

If you’re new to Docker and all this seems a bit complex, no worries. I will do a separate article on docker configuration with a detailed instruction very soon.

Now you can ssh into your server and run your project with docker-compose up -d. You can even scale it with docker-compose up -d --scale web=3

3. Configuring nginx

Now that the project is running on the server, we need to make it publicly available by configuring Nginx.

We need to create a new file /etc/nginx/sites-enabled/todox:

Then, simply reload the Nginx config.

Conclussion

I hope by that time you have at least an overview of how my setup works. In the next articles, I’m planning to elaborate on many of the topics we talked about here including Docker and Nginx setup.

I’d be happy to answer any questions (you can write to me in Twitter DM)

where to go from here

Recent Posts

Categories

Meta