Sadık Ay

Step By Step Deploying Rails Application

May 20, 2015 | 2 Minute Read

Deploying Rails on Ubuntu Digitalocean, Nginx, Unicorn, Mina

In the this post I ll try to make I tutorial about deploying of Rails Applications by solving issues which I got. So, I think for rails developers the most painful sections is: Deploying (specially first deploy).

I ll start from assuming your Rails app works properly in localhost and it have configured on VCS (github etc.)

If you have an account on Digitaloceon, Login and create a droplet like in following way. In the case of you have not an account on Digitalocean you can Sign In by using my referral link.

Step 1 - Creating new droplet on Digitalocean

Create your droplet as requirements of your application. For smaller applications it is enough to use 512 MB RAM - 20 GB SSD plan.

The next step is to choose your location. Choose one close to you so that you can have better connection speeds.
In the next step, we need to choose which OS to use. We ll choose Ubuntu 14.04-64 in this post. Optionally you can choose Ruby on Rails on 14.04 (Nginx + Unicorn) in ‘Aplication’ section. You can add your SSH-key into the droplet as optionally as well.

Step 2 - Adding SSH key to digitalocean

If you already have an SSH key in digitalocean you can choose it and skip this step.

Open new terminal on your local PC and run ssh-keygen command. Make sure your public key has been saved in /home/youruser/.ssh/id_rsa.pub
Then run cat .ssh/id_rsa.pub and copy display of your command and paste it to digitalocean SSH key content.

Step 3 - Adding new user on Ubuntu Server

Get your server IP from digitalocean panel and run ssh root@[serverIP] in your local terminal.

So, you have connected to your droplet. Let's start to create new user on your server and install requirements.

# adding new user
adduser deployer
visudo

# Search for the line that looks like this:
root ALL=(ALL:ALL) ALL

# add the new user permission below the root permission line
deployer ALL=(ALL:ALL) ALL

su deployer
cd
# you are on new user path rigt now :)

Step 3 - Creating SWAP area on your server

This step is not necessary for each system. You can googling about SWAP area. If you decide to SWAP area is not necessary for your system. You can skip this step.

    sudo fallocate -l 4G /swapfile
    sudo chmod 600 /swapfile
    sudo mkswap /swapfile
    sudo swapon /swapfile

Run the following command and check your SWAP area if exist and created correctly.

sudo swapon -s