Deploying rails apps, part 2. Setting up the necessary software


In the previous part of my articles I talk about bootstraping the server to prepare it to install neccessary software. Now we’ll install RVM, Node.js, Nginx, Ruby, Bundler and Postrgres.

Setting up the necessary software

So, the next step is setting up the RVM - tool to manage the versions of gems simplier.

Switching to root and the first thing we uprading the versions of sofware in the repository

  apt-get update
  apt-get dist-upgrade

Install some useful software we will need later:

  apt-get -y install curl git

Rvm, ruby, and bundler installation

Switch to deploy user:

  login deploy -f

And install rvm after that.

  gpg --keyserver hkp://keys.gnupg.net --recv-keys D39DC0E3
  \curl -sSL https://get.rvm.io | bash -s stable

Don’t forget to reload your shell to use rvm command.

Install ruby

  rvm install 2.1.1 (or version that you prefer)

Install bundler

  gem install bundler --no-ri --no-rdoc
  [[ -s "$HOME/.rvm/scripts/rvm" ]] && . "$HOME/.rvm/scripts/rvm"

Node.js installation.

Next install Node.js - Rails uses it to compile static assets. Don’t forget to switch to root or use sudo.

  add-apt-repository ppa:chris-lea/node.js
  apt-get -y update
  apt-get -y install nodejs

Nginx installation.

The next step is installing Nginx - it will serve our static requests.

  add-apt-repository ppa:nginx/stable
  apt-get -y update
  apt-get -y install nginx

And start nginx:

  service nginx start

PostgreSQL installation

My choice is using Postgres - it’s smart, clever and has very convenient console.

  apt-get install postgresql postgresql-contrib libpq-dev

During the installation PostgreSQL created ‘postgres’ user. So, let’s start to use database console as postgres user.

  sudo -u postgres psql

In the console:

  create role deploy superuser;
  alter role deploy login;

We’ve created new database user ‘deploy’, gave him superuser rights and allowed him to login. This user can login but only from the localhost.

The good way is not to use postgresql default config postgresql.conf. If you are not Postgres-guru you can set up the special tool called ‘pgtune’ that configures you database based on your environment.

  apt-get install pgtune

after that we should find postgresql.conf file to feed it to pgtune. Login to the “psql” console mentioned before and type.

  SHOW config_file;

Use \q for logout, then

  pgtune -i path/to/postgresql.conf -o path/to/postgresql.conf
  service postgresql restart

Summary

In this section we setting up the necessary software to serve rails application. In the next section I cover how to install and configure Capistrano with Puma server and how to configure Nginx.

Related Posts

Golang and OpenAPI(Swagger). How to create documentation for your REST API services

Game of Code Review. How code review can improve the health of your team

Active Admin custom JavaScript for diverse pages

Simple hack to add per page JS to active admin

The easiest way to localize SPA application using polyglot.js

The simplest way to localize your modern single page application

Presenters in javascript

An article describing using presenters in your javascript code

Deploying rails apps, part 3. Configuring capistrano, nginx with puma

The third article of deployment series. Configuring capistrano, nginx with puma

Deploying rails apps, part 1. Bootstrap the server

The first article of deployment series. Bootstrap the server.