Over a million developers have joined DZone.

Ruby-on-Rails Deployment on a Linode Server

DZone's Guide to

Ruby-on-Rails Deployment on a Linode Server

Follow along for a very detailed tutorial on deploying Ruby on Rails applications to the Cloud on Ubuntu Linux OS.

· Cloud Zone ·
Free Resource

Learn how to migrate and modernize stateless applications and run them in a Kubernetes cluster.

A couple of years ago, I got into this practice of hosting my applications on the cloud. At that time, AWS did not offer Ubuntu machines. I love Ubuntu, so I did not go to AWS. I also have this feeling that access and deployment procedures on the biggies (AWS and Azure) are slightly more cumbersome than the not-so-biggies. Among these, Site5 is the cheapest, but I don't get root access and was very disappointed with their lack of support. For $20 a month, I got a 4 GB RAM server on Linode compared to 2 GB RAM on Digital Ocean. Hence, I went with Linode.

I am the lone fella who designed and coded my application. Thus, I have not yet started using a git server, either on-premise or cloud. Since my MacBook has Time Machine enabled to my external hard disk, I get some sort of primitive version control. So my deployment procedure is to simply FTP my code to the server and restart the process. In this post, I am sharing the steps and commands I followed.

Of course, as the application and team size grows, a better methodology would be to put the code on a git branch, merge into a master, either pull or push it to the cloud server, then build and start the server. These steps can be automated with the help of tools like Capistrano.

My tech stack is Ruby, Rails, RVM, MySQL, Nginx, and Phusion Passenger. The two articles that give all details are here and here.

I had to do a few things and note a few other useful commands in addition to those given in these two articles. So, here we go.

Remote login and create a user with name deploy:
$ ssh root@my_ipaddress
--> Enter root password

Create user:
$ sudo adduser deploy
password : my_password
$ sudo adduser deploy sudo
$ exit

MacBook: Set up SSH keys:
$ ssh-keygen -t rsa
--> Press enter key
--> Enter passphrase
--> Enter same passphrase again

$ ssh-copy-id deploy@my_ipaddress

$ ssh deploy@my_ipaddress
Enter passphrase
Check Remember password in my keychain

$ 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 python-software-properties libffi-dev

$ sudo apt-get install libgdbm-dev libncurses5-dev automake libtool bison libffi-dev
$ gpg --keyserver hkp://keys.gnupg.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3
$ curl -sSL https://get.rvm.io | bash -s stable
$ source ~/.rvm/scripts/rvm
$ rvm install 2.3.1
$ rvm use 2.3.1 --default
$ ruby -v
$ gem install bundler

$ 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 nginx-extras passenger

$ sudo apt-get install mysql-server mysql-client libmysqlclient-dev
username: root
password: my_password

$ sudo vi /etc/nginx/sites-enabled/default

server {
  listen 80 default_server;
  listen [::]:80 default_server ipv6only=on;

  server_name my_ipaddress;
  passenger_enabled on;
  rails_env    production;
  root         /home/deploy/myapp/public;

  # redirect server error pages to the static page /50x.html
  error_page   500 502 503 504  /50x.html;
  location = /50x.html {
    root   html;
$ sudo vi /etc/nginx/nginx.conf 
 # Phusion Passenger config 
 # Uncomment it if you installed passenger or passenger-enterprise 
 include /etc/nginx/passenger.conf; 

 $ sudo mkdir myapp 
 $ cd myapp 


The code in your local folder should have mail configuration.
$ vi config/environments/production.rb 
  config.action_mailer.default_url_options = {host: 'localhost', port: 80}
  config.action_mailer.delivery_method = :smtp
  config.action_mailer.smtp_settings = {
    :authentication => :plain,
    :address => "smtp.mailgun.org",
    :port => 587,
    :domain => "mail.mydomain.com",
    :user_name => "postmaster@mail.mydomain.com",
    :password => "my_encrypted_password",
    :enable_starttls_auto => true

Launch FileZilla

Host : sftp://my_ipaddress -- Username: deploy -- Password: my_password

FTP all folders in the local app folder (except TMP) to the server: /home/deploy/myapp

Cloud Server

[Editor's Note: Due to a hiccup with our content management system, please see the original source for the cloud server configuration.] 

Then: $ sudo service nginx start  


Open Chrome browser, using the URL: http://my_ipaddress 


In case you want to do it all over again, login as root, stop nginx, delete user, purge nginx. 
$ pgrep -u deploy 
$ ps -f --pid $(pgrep -u deploy) 
$ killall -9 -u deploy 
$ deluser --remove-home deploy 

$ sudo apt-get purge nginx-extras passenger 
$ sudo apt-get purge nginx-common 
$ sudo apt-get autoremove 

Join us in exploring application and infrastructure changes required for running scalable, observable, and portable apps on Kubernetes.

cloud ,ruby ,rails ,ubuntu

Published at DZone with permission of

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}