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 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:// --recv-keys 561F9B9CAC40B2F7
sudo apt-get install -y apt-transport-https ca-certificates
sudo sh -c 'echo deb 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>

    # 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

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


ServerName localhost 

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

Install Ruby on Ubuntu 16.04

curl -sL | sudo -E bash -
curl -sS | sudo apt-key add -
echo "deb 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
tar -xzvf ruby-2.5.1.tar.gz
cd ruby-2.5.1/
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

Create your own user feedback survey