Yu-Chieh’s Blog (Y.C. Chang)

Ruby on Rails / Rubygems / FullStack / Git / Mac notes.

Deploy Ruby on Rails App on Ubuntu 14.04 by Mina

  • Mina is fast and easy deploy tool for ruby on rails app (especially faster than capistrano). This note shows how to deploy ruby on rails app by mina.

  • Start up an ubuntu server (here we use Ubuntu 14.04 LTS x64 on vultr cloud server)

  • ssh to login your server

1
$ ssh username@123.123.123.123
  • create a new user for later deployment work, better use the same name as your local development user name
1
2
3
$ sudo adduser new_user
$ sudo adduser new_user sudo
$ su new_user
  • We’re going to exploit ssh-copy-id to setup SSH connection for saving our time.
1
2
$ brew install ssh-copy-id # on Mac we use brew
$ ssh-copy-id new_user@123.123.123.123
  • Next, we’re going to install Ruby and its bundler.
1
2
3
4
5
6
$ curl -L https://get.rvm.io | bash -s stable
$ source ~/.rvm/scripts/rvm
$ rvm install 2.2.0
$ rvm use 2.2.0 --default
$ echo "gem: --no-ri --no-rdoc" > ~/.gemrc
$ gem install bundler
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
# Install Phusion's PGP key to verify packages
$ gpg --keyserver keyserver.ubuntu.com --recv-keys 561F9B9CAC40B2F7
$ gpg --armor --export 561F9B9CAC40B2F7 | sudo apt-key add -

# Add HTTPS support to APT
$ sudo apt-get install apt-transport-https

# Add the passenger repository
$ sudo sh -c "echo 'deb https://oss-binaries.phusionpassenger.com/apt/passenger trusty main' >> /etc/apt/sources.list.d/passenger.list"
$ sudo chown root: /etc/apt/sources.list.d/passenger.list
$ sudo chmod 600 /etc/apt/sources.list.d/passenger.list
$ sudo apt-get update

# Install nginx and passenger
$ sudo apt-get install nginx-full passenger

# start service
$ sudo service nginx start
  • setup nginx
1
$ sudo nano /etc/nginx/nginx.conf
  • find lines below and uncomment them.
1
2
3
4
5
6
7
8
9
10
11
##
# Phusion Passenger
##
# Uncomment it if you installed ruby-passenger or ruby-passenger-enterprise
##

passenger_root /usr/lib/ruby/vendor_ruby/phusion_passenger/locations.ini;

#passenger_ruby /home/new_user/.rbenv/shims/ruby; # If you use rbenv
passenger_ruby /home/new_user/.rvm/wrappers/ruby-2.2.0/ruby; # If use use rvm, be sure to change the version number
# passenger_ruby /usr/bin/ruby; # If you use ruby from source
  • installing mysql
1
$ sudo apt-get install mysql-server mysql-client libmysqlclient-dev
  • installing locale and set it up ref
1
2
3
4
5
6
7
8
$ sudo nano /var/lib/locales/supported.d/local # add locales you want to use
# zh_TW.UTF-8 UTF-8

$ sudo locale-gen
# regenerate locales

$ sudo nano /etc/default/locale
# set all as your preferal locale

-installing nodejs for coffee script engine

1
$ sudo apt-get install nodejs
  • installing git for pull remote git repo
1
$ sudo apt-get install git
  • installing nginx
1
$ sudo apt-get install nginx
  • installing imagemagick for paperclip resize image
1
$ apt-get install imagemagick
  • installing unicorn
1
$ gem install unicorn
1
2
3
4
5
6
7
8
9
10
11
12
# go to rails app which your want to deploy and inialize your deploy config file

$ mina init

# login and setup your server and create folders for later deployment

$ ssh username@123.123.123.123
$ sudo mkdir -p "/var/www/demo.com" && sudo chown -R new_user "/var/www/demo.com"

$ mina setup # after tweak your mina deploy.rb file, run this.

$ mina deploy # if mina setup is allpass, run this.
  • mina init will created config/deploy.rb. after this you might want to customize your deploy.rb file.

  • done.

Comments