Setting up Linode Box for Rails App Deployment

Linode Box Initial Setup

I had to rebuild Linode image because I selected redirect option during letsencrypt SSL installation. Do not redirect option works.

Ubuntu 16.04

After selecting the Linux version and stuff, you are now ready to boot the machine.

Rebuild Linode Boot

Click on Boot button and say OK to the popup window.

Linode Boot

This will boot the machine. You can setup the SSH access with root password. Create a deploy user on that box to deploy Rails apps using Capistrano. You can check the installed Ubuntu version:

$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 16.04.4 LTS
Release:    16.04
Codename:   xenial

Install Rails Stack on Ubuntu

$ ssh root@IP-OF-LINODE-BOX

Using Lish:

ssh -t your-linode-id@lish-some-city.linode.com linode123456

Create a deploy user

root@localhost:~# sudo adduser deploy

On Mac install ssh-copy-id that will copy the ssh keys to the server.

brew install ssh-copy-id

You can use the ssh-copy-id command:

ssh-copy-id deploy@IPADDRESS

This failed for me because I rebuilt the image. I had to remove the ssh key entry for the IP address of the Linode box in your .ssh/known_hosts file on your laptop.

Installing Passenger + Apache

Run these commands:

sudo apt-get install -y dirmngr gnupg
sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 561F9B9CAC40B2F7
sudo apt-get install -y apt-transport-https ca-certificates
sudo sh -c 'echo deb https://oss-binaries.phusionpassenger.com/apt/passenger xenial main > /etc/apt/sources.list.d/passenger.list'
sudo apt-get update
sudo apt-get install -y libapache2-mod-passenger
sudo a2enmod passenger

Running the a2enmod command failed:

sudo: a2enmod: command not found

Install Apache

sudo apt-get install apache2

Now the command will work:

sudo a2enmod passenger
   Enabling module passenger.
   To activate the new configuration, you need to run:
     service apache2 restart

We can restart the webserver:

service apache2 restart

Virtual Host Entry for Subdomain

Add VirtualHost entry:

<VirtualHost *:80>
    ServerName letsdance.joaquinamenabar.com

    # Tell Apache and Passenger where your app's 'public' directory is
    DocumentRoot /home/deploy/tango/current/public

    PassengerRuby /usr/local/bin/ruby

    <Directory "/home/deploy/tango/current/public">
      Allow from all
      Options -MultiViews
      Require all granted
    </Directory>
</VirtualHost>

to : /etc/apache2/apache2.conf file.

Retart the server:

sudo apachectl restart

I got the warning:

Could not reliably determine the server's fully qualified domain name, using ::1. Set the 'ServerName' directive globally to suppress this message

You can fix this warning:

vi /etc/apache2/apache2.conf

Add:

ServerName localhost 

Now you have view default Apache 'It works' static web page.

Install Ruby on Ubuntu 16.04

curl -sL https://deb.nodesource.com/setup_8.x | sudo -E bash -
curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | sudo apt-key add -
echo "deb https://dl.yarnpkg.com/debian/ stable main" | sudo tee /etc/apt/sources.list.d/yarn.list
sudo apt-get update
sudo apt-get install git-core curl zlib1g-dev build-essential libssl-dev libreadline-dev libyaml-dev libsqlite3-dev sqlite3 libxml2-dev libxslt1-dev libcurl4-openssl-dev software-properties-common libffi-dev nodejs

I am not installing yarn because I am deploying a Rails 5 app.

cd temp
wget http://ftp.ruby-lang.org/pub/ruby/2.5/ruby-2.5.1.tar.gz
tar -xzvf ruby-2.5.1.tar.gz
cd ruby-2.5.1/
./configure
make
sudo make install
ruby -v

You can now install bundler.

gem install bundler

In this article, we saw how to setup a new Linode box for Rails app deployment. We installed Apache, Passenger, Ruby 2.5.1 and bundler. We can now setup Capistrano to deploy a Rails app.


Related Articles


Ace the Technical Interview

  • Easily find the gaps in your knowledge
  • Get customized lessons based on where you are
  • Take consistent action everyday
  • Builtin accountability to keep you on track
  • You will solve bigger problems over time
  • Get the job of your dreams

Take the 30 Day Coding Skills Challenge

Gain confidence to attend the interview

No spam ever. Unsubscribe anytime.