In this tutorial we are going to setup an AWS EC2 instance for deployment of rails application.

Server Setup

Following is the setup instruction for ubuntu 16.04 using ruby 2.4, Postgres 9.6 and rails 5.

Installing Ruby

Setting up dependencies for ruby.

Next step is to install ruby using RVM.

Last step is to install bundler.

Installing Rails

Installing NodeJS, this lets you use Coffee script and the Asset Pipeline in Rails which combines and minifies your javascript to provide a faster production environment.

Next is to install rails.

You can verify the installation of rails version.

Installing PostgreSQL

The postgres installation doesn’t setup a user for you, so you’ll need to follow these steps to create a user with permission to create databases.

Install Nginx

Following are some basic commands to manage Nginx:

Nginx Configuration

First disable default site by removing the symlink.

Now create a new virtual host config file.

edit the my_app.conf file:

Puma Configuration

Change config/puma.config file according to following example:

Create puma upstart script

Let’s create an Upstart init script so we can easily start and stop Puma.

Now open the provided puma.conf file, so we can configure the Puma deployment user.

Look for the two lines that specify setuid and setgid, and replace “apps” with the name of your deployment user and group.

Now copy the scripts to the Upstart services directory.

The puma-manager.conf script references /etc/puma.conf for the applications that it should manage. Let’s create and edit that inventory file now.

Each line in this file should be the path to an application that you want puma-manager to manage. Add the path to your application now. For example.

Jungle upstart script provides following commands to manage puma app server:

Install Mina

Add in your Gemfile.

and run bundle install to install mina.

Create deployment script

It will create config/deploy.rb, let’s edit it as following:

Now to setup directory structure run:

To deploy the application run: