Bacancy Bacancy
  • Customers

      Fortune 500 Clients

      Verizon
      Verizon
      Franklin Templeton
      Franklin Templeton
      The Container Store
      The Container Store
      KPMG
      KPMG
      Academy Sports & Outdoors
      Academy Sports & Outdoors
      Shell
      Shell
      Bangkok Bank Ltd
      Bangkok Bank Ltd
      The Children's Place
      The Children's Place
      Edward Jones
      Edward Jones
      United Parcel Service
      United Parcel Service
      AdviceWorks
      AdviceWorks
      NatWest Markets
      NatWest Markets
      Bridgestone
      Bridgestone

      Technologies

      React JS VueJS Angular JS React Native Flutter Full Stack
      Ruby on Rails Node JS Golang AI & ML Data Science Java
      Python Salesforce DevOps Block Chain Mobile App Embedded & Hardware
      Explore All
      skype-icon

      Skype ID

      bacancy
      gmail-icon

      Email Us

      [email protected]
      call-yellow-icon

      USA

      +1 347 441 4161
      wp-icon

      Canada

      +1 416 907 6738
  • what we do

      Experience

      Digital Workplace Services Product Enhancement

      Insights

      AI & Automation Data Analytics

      Innovate

      Blockchain Software Engineering Services Internet of Things (IoT) Data Science Artificial Intelligence Machine Learning

      Accelerate

      Cloud - Bacancy Combalt Digital Process Automation Open Source Microsoft Dynamics Salesforce

      Assure

      Quality Assurance IT Staff Augmentation

      Embedded & Hardware

      Product Engineering Analog Design Services FPGA Engineering Service Wireless Design Embedded Software Design

      not list

      Hardware Engineering Power Engineering IoT Hardware
      skype-icon

      Skype ID

      bacancy
      gmail-icon

      Email Us

      [email protected]
      call-yellow-icon

      USA

      +1 347 441 4161
      wp-icon

      Canada

      +1 416 907 6738
  • who we work with

      Industries

      Banking Financial services & Insurance Startups Oil & Gas

      not list

      Healthcare Life Science Real Estate & Construction Logistics
      bacancy

      Let’s grow together Partner with us

      get quote
      skype-icon

      Skype ID

      bacancy
      gmail-icon

      Email Us

      [email protected]
      call-yellow-icon

      USA

      +1 347 441 4161
      wp-icon

      Canada

      +1 416 907 6738
  • about us

      Culture

      Agile Mindset Bacancy Values Bacancy Culture

      About Company

      About Us Leadership Team Awards & Recognition Infrastructure

      not list

      Customer Reviews Our Locations Partnership Media Coverage

      WE ARE

      GREAT PLACE TO WORK - CERTIFIEDTM

      Building and sustaining High-Trust, High-Performance CultureTM

      Bacancy Great Place to Work
      skype-icon

      Skype ID

      bacancy
      gmail-icon

      Email Us

      [email protected]
      call-yellow-icon

      USA

      +1 347 441 4161
      wp-icon

      Canada

      +1 416 907 6738
  • technology

      Front End

      Angular Reactjs Vue.js UI/UX

      Platforms

      MS Dynamics Salesforce

      Back End

      Ruby on Rails Node.js Golang Laravel .NET Java Python

      Mobile

      React Native Flutter Android iOS

      Cloud

      AWS DevOps

      QA

      Automation Testing Software Testing

      Embedded & Hardware

      Embedded
      bacancy

      World-class expertise,Delivered

      get quote
      Explore All
      skype-icon

      Skype ID

      bacancy
      gmail-icon

      Email Us

      [email protected]
      call-yellow-icon

      USA

      +1 347 441 4161
      wp-icon

      Canada

      +1 416 907 6738
  • PRODUCTS

      EV Products

      Battery Management System Motor Controller AC Charger Explore All

      not list

      CCS2 Controller DC Fast Charger AC Charge Controller
      bacancy

      Let’s grow together Partner with us

      get quote
      skype-icon

      Skype ID

      bacancy
      gmail-icon

      Email Us

      [email protected]
      call-yellow-icon

      USA

      +1 347 441 4161
      wp-icon

      Canada

      +1 416 907 6738
hire developers

Bacancy

Bacancy represents the connected world, offering innovative and customer-centric information technology experiences, enabling Enterprises, Associates and the Society to Rise™.

12+

Countries where we have happy customers

1050+

Agile enabled employees

06

World wide offices

10+

Years of Experience

05

Agile Coaches

14

Certified Scrum Masters

1000+

Clients projects

1458

Happy customers

  • Customers
      Technologies
      • React JS
      • Angular JS
      • Vue JS
      • Node JS
      • AI & ML
      • Explore All
      Fortune 500 Clients
      • Verizon
      • The Container Store
      • KPMG
      • Academy Sports & Outdoors
      • Bangkok Bank Ltd
      • The Children's Place
      • Edward Jones
      • Franklin Templeton
      • AdviceWorks
      • NatWest Markets
      • Bridgestone
      • United Parcel Service
  • What we do
      Experience
      • Digital Workplace Services
      • Product Enhancement
      Insights
      • AI & Automation
      • Data Analytics
      Innovate
      • Blockchain
      • Software Engineering Services
      • Internet of Things (IoT)
      Accelerate
      • Cloud - Bacancy Combalt
      • Digital Process Automation
      • Open Source
      • Microsoft Dynamics
      • Salesforce
      • Service Experience Transformation
      Assure
      • Testing
      • Resource Augmentation
      Embedded & Hardware
      • Product Engineering
      • Analog Design Services
      • FPGA Engineering Service
      • Wireless Design
      • Embedded Software Design
      • Hardware Engineering
      • Power Engineering
      • IoT Hardware
      • AL/ML
  • who we work with
      Industries
      • Banking Financial services & Insurance
      • Startups
      • Oil & Gas
      • Healthcare Life Science
      • Real Estate & Construction
      • Logistics
  • About Us
      About Company
      • About Us
      • Leadership Team
      • Awards & Recognition
      • Infrastructure
      • Our Locations
      • Partnership
      Culture
      • Agile Mindset
      • Bacancy Values
      • Bacancy Culture
  • Technology
      Front End
      • Angular
      • Reactjs
      • Vue.js
      • UI/UX
      Platforms
      • MS Dynamics
      • Salesforce
      Back End
      • Ruby on Rails
      • Node.js
      • Golang
      • Laravel
      • .NET
      • Java
      • Python
      Mobile
      • React Native
      • Flutter
      • Android
      • iOS
      Cloud
      • AWS
      • DevOps
      QA
      • Automation Testing
      • Software Testing
      Embedded & Hardware
      • Embedded
      Explore All
  • Products
    • Battery Management System
    • Motor Controller
    • CCS2 Controller
    • AC Charger
    • DC Fast Charger
    • AC Charge Controller
    • Explore All
  • Careers
  • Work @ Bacancy
  • Blogs
  • Resources
  • Customer Reviews
  • Contact
  • Get Quote

How to Deploy Rails App With Capistrano?

How to Deploy Rails App With Capistrano?
Last Updated on February 28, 2023
December 20, 2018 4 min read

Being a software developer it’s a part of routine job to perform on assigned tasks, do the required changes, build new features and make it live to production. All of these stuff such as taking pull from branch, migrating, bundling and seeding is a tedious process. Almost every other developer is in need of a tool to ease things up.

If you are looking for automating deployment, then one tool is already there called Capistrano. I am writing this technical blog to help you understand that how to deploy a Rails application to AWS using Capistrano.

For better understanding, consider that you are using the Passenger + Nginx + PostgreSQL. Passenger is the application server, Nginx is the reverse proxy, and PostgreSQL is the database server.

So, before you proceed for deployment it is must to have an existing application and one server. i.e. We will be using AWS Ec2 instance. For more details on how to create EC2 Instance please visit, https://www.bacancytechnology.com/blog/aws-ec2-how-to-create-ec2-instance-from-scratch”

After, creating instance you have to setup environment that is able to run Rails app for the listed below steps :

Step 1: Setup the Server

- sudo apt-get update
- sudo apt-get install build-essential libssl-dev libyaml-dev libreadline-dev openssl curl git-core zlib1g-dev bison libxml2-dev libxslt1-dev libcurl4-openssl-dev nodejs libsqlite3-dev sqlite3

Note: Based on Database used on your rails app you have to install that in this server, for example, Postgres or Mysql

Install RVM & Ruby

curl -sSL https://get.rvm.io | bash -s -- --path /home/ubuntu/.rvm	 	 	
export rvm_path=/home/ubuntu/.rvm	 	 	
rvm install 2.4.2

Install Git and add SSH

Step 2: Let’s start by configuring each module one by one

Configuring Passenger & Capistrano

Please add below gems in your Gem file

group :development do
 gem 'capistrano', require: false
 gem 'capistrano-rvm', require: false
 gem 'capistrano-rails', require: false
 gem 'capistrano-bundler', require: false
 gem 'capistrano-passenger', require: false
end

Note: For more details on GEM please visit : https://github.com/capistrano/capistrano

Step 3: Install bundle and generate Capistrano config files

-After adding Gem into Gemfile run ‘bundle install’

– Now after successful installation for all gem it’s time to configure Capistrano,

- cap install cap install STAGES=production

Above command will generate a list of file for configuring Capistrano such as config/deploy.rb and config/deploy/production.rb

Install bundle and generate Capistrano config files
Step 4: Configure Capistrano Files

For the first file, we have to configure Capfile to paste below lines into your Capfile. Search Capfile in your rails App root directory.

# Load DSL and set up stages
			require "capistrano/setup"
			require "Capistrano/deploy"

			require "capistrano/scm/git"
			install_plugin Capistrano::SCM::Git

			require 'capistrano/setup'
			require 'Capistrano/deploy'

			require 'Capistrano/rails'
			require 'Capistrano/bundler'
			require 'Capistrano/rvm'
			require 'Capistrano/passenger'
			require "whenever/Capistrano"

		Dir.glob("lib/capistrano/tasks/*.rake").each { |r| import r }

Note : this file is already added in your cap file you just have to uncomment it or replace all with the above code.

Step 5: Configure deploy.rb

# config valid only for the current version of Capistrano

lock "3.10.2"

		server '54.88.139.244', port: 22, roles: [:web, :app, :db], primary: true

		set :repo_url, '< repo url >'
		set :application, < app_name >'
		set :user, 'ubuntu' #server user

		set :rvm_bin_path, "$HOME/bin"
		set :rvm_ruby_version, '[email protected]_name'

		# Don't change these unless you know what you're doing
		set: pty, true
		set :use_sudo, false
		set :rails_env, "production"
		set :stage, :production
		set :deploy_via, :remote_cache
		set :deploy_to, "/home/#{fetch(:user)}/apps/#{fetch(:application)}"

		set :ssh_options, { forward_agent: true, user: fetch(:user), keys: %w(~/.ssh/id_rsa) }

		set :branch, :< branch name >

		namespace: deploy do

		desc 'Initial Deploy'
		task: initial do
		on roles(:app) do
		before 'deploy: restart'
		invoke 'deploy'
		end
		end

		set :linked_files, %w{config/database.yml}

		after :finishing, :compile_assets
		after :finishing, :cleanup
		after :finishing, :restart
		end

– In deploy.rb change following things

Set your ip
Set your repository
Set application name
Set user
Set rvm path as per your installation
Set deploy_to path
Set linked_file (It’s secret files that is confidential for your application. We need to create symbolic on a server for that files)

Step 6: Create a Symbolic link

– You have to create a symbolic link for storing Credential like database.yml and .env

– For that Create directory in this structure app_name/shared/config/database.yml
e.g. sudo vi /home/ubuntu/apps/blog__app/shared/config/database.yml

Step 7: Install and configure passenger-Nginx

sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 561F9B9CAC40B2F7

– Edit below file

sudo vi /etc/apt/sources.list.d/passenger.list

– Add below line in that file

deb https://oss-binaries.phusionpassenger,com/apt/passenger xenial main

– Save that file and exit

And run below command in terminal

- sudo chown root: /etc/apt/sources.list.d/passenger.list
- sudo chown ubuntu: /etc/apt/sources.list.d/passenger.list
- sudo chmod 600 /etc/apt/sources.list.d/passenger.list

- sudo apt-get update

- sudo apt-get install nginx-extras passenger

After installation done open Nginx configuration file and uncomment below the line.

# Uncomment it if you installed passenger or passenger-enterprise include /etc/nginx/passenger.conf;

By running below command

- sudo vi /etc/nginx/nginx.conf
user www-data;
worker_processes auto;
pid /run/nginx.pid;

events {
worker_connections 768;
# multi_accept on;
}

http {
# Basic Settings

sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;

include /etc/nginx/mime.types;
default_type application/octet-stream;

access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;

# Gzip Settings

gzip on;
gzip_disable "msie6";

# Uncomment it if you installed passenger or passenger-enterprise
include /etc/nginx/passenger.conf;

# Virtual Host Configs

include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*;
}
- sudo vi /etc/nginx/passenger.conf

Check passenger.conf that passenger ruby is there, if your file contains below two line your good to go

passenger_root /usr/lib/ruby/vendor_ruby/phusion_passenger/locations.ini;
passenger_ruby /usr/bin/passenger_free_ruby;

Step 8: Create or edit nginx site-enable/site-available, as described below,

- sudo vi /etc/nginx/sites-enabled/default
server {
      listen 80 default_server;
      server_name < IP >;
      #server_name < hostname >;
      passenger_enabled on;
      passenger_app_env production;
      passenger_app_group_name production;
      root /home/ubuntu/apps/app_name/current/public;
    }

Note: Please change the root path according to your application location.

At Last just run command :

cap production deploy

and restart Nginx server using below command

sudo service nginx restart

Related Article: Why You Should Deploy Your Rails App with Capistrano


Expand Your Digital Horizons With Us.

Start a new project or take an existing one to the next level. Get in touch to start small, scale-up, and go Agile.


Or
E-mail us : [email protected]

Your Success Is Guaranteed !

Related Articles

ruby on rails for fintech
Paridhi Wadhwani

March 17, 2023

Ruby on Rails

Ruby on Rails for FinTech App: Accelerating Business

By : Paridhi Wadhwani

Quick Summary: Want to build a breakthrough application in the FinTech domain? Ensure that the backend technology is robust, secure, and scalable. Ruby on Rails...

10 Minute Read
Read More
Ruby on Rails Statistics and Facts
Paridhi Wadhwani

February 27, 2023

Ruby on Rails

Ruby on Rails Statistics and Facts 2023

By : Paridhi Wadhwani

Preface Ruby on Rails is a popular choice for startup companies and small businesses due to its ease of use, rapid development capabilities, and low...

8 Minute Read
Read More
Hotwire Rails
Paridhi Wadhwani
Isha Gupta

January 30, 2023

Ruby on Rails

How to Use Hotwire Rails: Getting Started Tutorial

By : Paridhi Wadhwani & Isha Gupta

Introduction We are back with another exciting and much-talked-about Rails tutorial on how to use Hotwire with the Rails application. This Hotwire Rails tutorial is...

10 Minute Read
Read More
india India (HQ)

Corporate House
15-16, Times Corporate Park, Thaltej, Ahmedabad, Gujarat 380059

USA USA

601 Brickell Key Drive, Suite 700, Miami, Florida, 33131, USA

canada Canada

71 Dawes Road, Brampton, On L6X 5N9, Toronto

australia-flag Australia

351A Hampstead Rd, Northfield SA 5085

UAE UAE

1608 Clover Bay, Business Bay, Dubai, UAE. PO Box 62049

sweden Sweden

Junkergatan 4, 126 53 Hagersten


Great Place to Work
Get in Touch
call-yellow-icon

Contact Number

+1 347 441 4161

gmail-icon

Email Us

[email protected]


  • Bacancy Behance
  • Bacancy Uplabs
  • Bacancy Pinterest
  • Brochure
  • Quality Assurance
  • Resources
  • Tutorials
  • Customer Reviews
  • Privacy Policy
  • FAQs
  • Contact Us
  • Sitemap
  • Employee
bacancy google review 4.6
bacancy google review
bacancy glassdoor review 4.5
bacancy glassdoor review
bacancy clutch review 4.8
bacancy clutch review
bacancy goodfirms review 4.5
bacancy goodfirms review
X

Get Our Newsletter

Be The First To Get The Latest Updates And Tutorials.

Request A Free Consultation

Before You Go...

Try our free consultation to visualize the best outcome of your business ideas.

INSTANT 30 MIN FREE CONSULTATION CALL