Ubuntu Server Preparation

Elixir is a compiled language and therefore needs to be "built" into releases before being started. It also needs to be built on the same operating system it is intended to run on, Ubuntu 18.04 in our case.

Edeliver & Distillery are our weapons of choice and just so we understand the process and how these tools work together here's an overview:

Create a Server

Create a new droplet, choose Ubuntu 18.04, your region and fire it up.

NOTE: Keep in mind that while running a Phoenix application takes very little memory, we'll need at least 2GB of memory to build the application. With any less the build process will run out of memory and fail.

Create deploy User

First we'll create a non-root user for deploying, aptly named deploy.

1. Log in to your new server as root and run:

$ sudo adduser deploy

Enter a password, and skip filling out details if you like.

2. With the deploy user created we need to add it to sudoers and to allow them to run sudo commands.

$ usermod -aG sudo deploy

3. Next, let's allow the user to use sudo without entering a password.

Record the details somewhere secure as we'll need them later when we deploy the application.

Install Nginx

Pretty straightforward here:

$ sudo apt update$ sudo apt -y install nginx

Verify it's installed:

$ sudo nginx -vnginx version: nginx/1.14.0 (Ubuntu)

Configuration for Nginx will be handled in a separate post. We're just focused on preparing the production environment for now.

Create an A Record for Domain

Let's create an A record pointing to the server IP address so it'll propagate by the time we have our app in production.

We use cloudflare for DNS but log in to your domain registrar and create the A Record either on the root or sub-domain.

Nginx should be running at this point so you should see the default page if you load the your domain in the browser:

Systemd

Comes with Ubuntu so no action to take here.

Wrapping Up.

So far we have laid the groundwork and focused on preparing the production server for building and running a Phoenix Application.

It can be tedious to manage your own server so this series has intentionally tried to keep things as simple as possible to reduce the surface area for issues to crop up while deploying our Phoenix App.

In the next part of this series, we'll prepare our phoenix application for deployment using Distillery to build releases and Edeliver.