0% found this document useful (0 votes)
57 views8 pages

Deploy A Rails App: To Heroku &&ubuntu Server

This document provides instructions for deploying a Rails application to Heroku and an Ubuntu server. It outlines setting up git tracking, creating a Heroku remote, deploying code to Heroku, migrating databases, and visiting the application in a browser. It also provides steps for setting up an Ubuntu server with Ruby, Rails, Node.js, creating database and SSH keys, installing Nginx, Unicorn, and using Capistrano for automated deployments.

Uploaded by

huvo1412
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
57 views8 pages

Deploy A Rails App: To Heroku &&ubuntu Server

This document provides instructions for deploying a Rails application to Heroku and an Ubuntu server. It outlines setting up git tracking, creating a Heroku remote, deploying code to Heroku, migrating databases, and visiting the application in a browser. It also provides steps for setting up an Ubuntu server with Ruby, Rails, Node.js, creating database and SSH keys, installing Nginx, Unicorn, and using Capistrano for automated deployments.

Uploaded by

huvo1412
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 8

DEPLOY A RAILS APP

TO HEROKU
&&UBUNTU SERVER
Deploy to HEROKU Server
Tracking your app in git

$cd myapp

$ git init

$ git add .

$ git commit -m "my first commit

Creating a Heroku remote

$ heroku create

You can verify the remote in your git configuration as well:

$ git remote v

heroku https://git.heroku.com/myapp.git (fetch)

heroku https://git.heroku.com/myapp.git (push)

Deploying code

$ git push heroku master

Migrate your database

$ heroku run rake db:migrate

Visit your application

$ heroku open
Setup Server on Ubuntu
# Setup the SSH server to use keys for authentication
https://www.g-loaded.eu/2005/11/10/ssh-with-keys/
# Add user deployer
$ sudo su
$ adduser deployer
$ passwd deployer # deployer
# Install dependencies
$ 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

# Install Nginx
$ sudo apt-get update
$ sudo apt-get install nginx
As deployer
# sudo su deployer

# Install libreoffice, path may varies depend on version - as deployer


$ cd ~
$ wget download.nus.edu.sg/mirror/tdf/libreoffice/stable/5.3.2/rpm/x86_64/LibreOffice_5.3.2_Linux_x86-64_rpm.tar.gz
$ tar -zxvf LibreOffice_5.3.2_Linux_x86-64_rpm.tar.gz
$ cd LibreOffice_5.3.2.2_Linux_x86-64_rpm/RPMS/
$ rm -f libobasis5.3-gnome-integration-5.3.2.2-2.x86_64.rpm
$ cd ..
$ ./install . ~/libreoffice
# Install Ruby
$ git clone https://github.com/rbenv/rbenv.git ~/.rbenv
$ git clone https://github.com/sstephenson/ruby-build.git ~/.rbenv/plugins/ruby-build
$ cd ~/.rbenv && src/configure && make -C src
$ export PATH="$HOME/.rbenv/bin:$HOME/.rbenv/shims:$PATH"
$ source ~/.bashrc
$ rbenv install 2.2.3
$ rbenv global 2.2.3
$ gem install bundler
$ gem install rails

# Install Javascript Runtime

$ sudo add-apt-repository ppa:chris-lea/node.js


$ sudo apt-get update
$ sudo apt-get install nodejs
# Create ssh key and add to github as deploy key
# Prepare folders as root
$ mkdir -p /var/www/myapp/shared/config #sudo
$ chown deployer:deployer /var/www/myapp
touch /var/www/myapp/shared/config/database.yml
# add to deployer/.bashrc
# rbenv
export RBENV_ROOT=/home/deployer/.rbenv
export PATH="${RBENV_ROOT}/bin:$PATH"
eval "$(rbenv init -)"
export PATH="${RBENV_ROOT}/shims:$PATH"

# Libreoffice
export PATH=$PATH:$HOME/libreoffice/opt/libreoffice5.3/program

# Rails ENV
export RACK_ENV="staging"
export RAILS_ENV="staging"
export PORT="80
export SECRET_KEY_BASE
Deploy to Server with Capistrano,
Unicorn and Nginx on Ubuntu
Capistrano is a framework for building automated deployment scripts. Although Capistrano itself is written in Ruby,
it can easily be used to deploy projects of any language or framework, be it Rails, Java, or PHP -
https://github.com/capistrano/capistrano
Install the Capistrano , Unicorn gem

gem 'whenever', require: false


gem 'unicorn
group :staging, :production do
gem 'capistrano'
gem 'capistrano-rails'
gem 'capistrano-bundler'
gem 'sepastian-capistrano3-unicorn', require: false
gem 'capistrano-rbenv'
end
"Capify" your project

$ bundle exec cap install


Add Unicorn configuration to config/unicorn.rb
Create Unicorn Init Script bin/unicorn.sh
Update the script's permissions and enable Unicorn to start on boot:
$ sudo chmod 755 /etc/init.d/unicorn_appname
$ sudo update-rc.d unicorn_appname defaults
Start it:
$ sudo service unicorn_appname start
Configure Nginx
sudo nano /etc/nginx/sites-available/default
Restart Nginx to put the changes into effect:
sudo service nginx restart
Deploy your app
$ cap production deploy

Get file and more details: https://www.digitalocean.com/community/tutorials/how-to-deploy-a-rails-app-with-unicorn-and-nginx-on-ubuntu-


14-04

You might also like