Josh Software

Deployment Using Mina – Josh Software

josh ruby

Deployment Using Mina – Josh Software

Mohammad Baniasad 2013-07-31 06:45:31

Got a nice web app and want to deploy and you have no clue about deployment of a rails app.. well that’s exactly me 2 days ago… here I’m sharing what I have learnt


  1. You have a working app called your_rails_app.
  2. You have access to a linux server with a working nginx server on
  3. Your app is also on github.

Introducing Mina

We are going to use mina gem for deployment so add mina gem to Gemfile. I used latest code in github, the reason was the current version 0.2.1 has some issues (after entering the user name for connecting to server, there was no response) so it should be like this in your gem file

gem “mina”, :git => ‘git://’
and run
bundle install

Configuration for mina
mina uses a configuration file for deployment, to create this file run

mina init

this would make a sample file under the config

before changing the settings in the file connect to server and create a directory ready for your app

mkdir /home/user_name/sitedir

Note that the user which you are using to connect to the server should have full access to this folder so grant the permissions

chown -R user_name /home/user_name/sitedir

now we have to config mina to deploy our app to this folder. open config/deploy.rb
change the following lines according to your needs

set :domain, '' 
set :deploy_to, '/home/user_name/sitedir'
set :repository, '"
set :branch, 'master'
set :user, 'user_name'
set :rail_env, 'production'

Mina manages your app in different versions and it uses a common log and config which is shared among these versions, the deployment script creates this file. we have to change it to use mongoid

queue! %[touch "#{deploy_to}/shared/config/mongoid.yml"

so ready to create our app’s structure? run

mina setup --verbose
# I always prefer to use --verbose switch to see whats happening

you may have noticed the message that tells you to change database.yml file. it’s because we have not changed the echo line to show mongoid.yml instead. change it if you like to!!
remember: we are using mongo so there would be no migrations comment this line
now if you look in the server side you would have 2 new dirs in your sitedir.
releases #holds your apps diffrent versions
shared #holds common features among your defferent versions. log and config are here

we are ready for first deploy. so run

mina deploy

Here you need to supply password for server.
if you are using a ssh handle for git you should configure the server to have access to your repository. I have used https address which in each deployment it asks for git user-name and password

Mina would invoke “bundle install “, if you are using rvm in the server this line would return an error
bundle: command not found
to fix this just uncomment this line in deploy.rb

require 'mina/rvm'

and invoke the ruby version in this line

# invoke :'rvm:use[ruby-1.9.3-p125@default]'

Now the rails app is up there int the server but first we should tell our nginx server how to look for our app and send the requests there , so open nginx configuration file: /opt/nginx/conf/nginx.conf
and add this lines to bottom of the file

listen 80;
root /home/siva/mohammad/sitedir/current/public/; 
passenger_enabled on;
rails_env production;

there can be several sites listening on the same port
if you want your site to be the default loading site add default_server property to the listen attribute

listen 80 default_server;

save the file. note that this file is write protected and needs to be open as super user

restart nginx

./opt/nginx/sbin/nginx -s stop

so it’s possible to have multiple apps on listtening on one port so  you should configure your system to send the request properly. so open host file

/etc/hosts on  your local ubuntu system
%systemroot%/system32/drivers/etc on your windows system

and add the following line to the end of file

open your browser and point to

there you go 🙂