-
Notifications
You must be signed in to change notification settings - Fork 138
/
Copy pathdeploy-rails-app.sh
158 lines (116 loc) · 3.86 KB
/
deploy-rails-app.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
# A list of commands - for quickly setting up VPS for deploying Rails Application
# using nginx, Ubuntu(Latest Stable LTS : 12.04), Unicorn, MySQL and Capistrano
# Author: Ramesh Jha (ramesh[at]rameshjha.com),(http://blog.sudobits.com)
# License: MIT
### Update! Also check out another deploy-with-passenger script
## for setting up Nginx/Passenger 5 for Rails/Sinatra on Ubuntu 14.04 LTS
# change root password
# setting hostname (optional)
echo "<YOUR_HOSTNAME>" > /etc/hostname
hostname -F /etc/hostname
# Update System Packages
apt-get -y update
apt-get -y upgrade
# Adding a swap (optional, required on Digital Ocean)
# 1 GB swap
sudo dd if=/dev/zero of=/swapfile bs=1024 count=1024K
sudo mkswap /swapfile
sudo swapon /swapfile
# add it to fstab so it's activated on reboot
# `vi /etc/fstab` and add following line
/swapfile none swap sw 0 0
# for security
sudo chown root:root /swapfile
sudo chmod 0600 /swapfile
# use `free -m` command to see if it's working or not
# fix for locale error on Ubuntu (optional)
apt-get install --reinstall language-pack-en
locale-gen en_US.UTF-8
# for apt
apt-get -y install python-software-properties
# install git and curl
apt-get -y install curl git-core
# Install Server (nginx)
apt-add-repository -y ppa:nginx/stable
apt-get -y update
apt-get -y install nginx
# start/stop nginx (in Ubuntu 12.04 LTS)
sudo service nginx start
sudo service nginx stop
sudo service nginx restart
# or
sudo /etc/init.d/nginx start
sudo /etc/init.d/nginx stop
sudo /etc/init.d/nginx restart
# For Installing nodejs
sudo apt-add-repository -y ppa:chris-lea/node.js
sudo apt-get -y update
sudo apt-get -y install nodejs
# Create User and add it to sudo group
adduser example_user --ingroup sudo
## setup keys for ssh login
# On Local Computer
ssh-keygen
scp ~/.ssh/id_rsa.pub example_user@IP_ADDRESS:
# On remote server
mkdir .ssh
mv id_rsa.pub .ssh/authorized_keys
# Install MySQL Database and its Dependencies
sudo apt-get -y install mysql-server libmysql++-dev
# for sqlite error
sudo apt-get install libsqlite3-dev
#create a production database (mysql)
mysql -u root -p
create database YOUR_DB_NAME;
grant all on YOUR_DB_NAME.* to DB_USER@localhost identified by 'your_password_here';
exit
# alternate : installing postgresql
sudo apt-get install postgresql-9.1 postgresql-contrib-9.1 redis-server \
libxml2-dev libxslt-dev libpq-dev make g++
# Create your postgres user and database
sudo -u postgres psql
# \password
# create user blog with password 'secret';
# create database blog_production owner blog;
# \q
## update .bashrc according to rbenv installer's instruction
# install dependencies
rbenv bootstrap-ubuntu-12-04
# latest ruby
rbenv install 2.0.0-p353
rbenv install 2.0.0-p353
rbenv rehash
rbenv global 2.0.0-p353
# install bundler and rake
gem install bundler --no-ri --no-rdoc
gem install rake --no-ri --no-rdoc
rbenv rehash
# setup git and github or bitbucket or equivalent one!
# remove default nginx config
sudo rm /etc/nginx/sites-enabled/default
# deployment using capistrano && unicorn
# update gemfile
# Deploy with Capistrano
# update Gemfile
## gem 'capistrano'
## gem 'mysql2'
## gem 'unicorn'
## gem 'capistrano'
bundle
# now capify!!
capify .
## update capfile and config/deploy.rb
## add config/nginx.conf
## add unicorn.rb
## add unicorn_init.sh and make it executable
## add delayed job scripts (rails generate delayed_job && capistrano recepies)
## commit the latest changes and update database.yml (youmay want to add it to gitignore file and
## and update it manually on the server, for security reasons, of course)
# Deploying to VPS
cap deploy:setup
cap deploy
# Run Database Migrations
cap deploy:migrate
# for delayed job and sending emails (if you're using)
cap deploy:start
## read this (and comment there) if you need any help : http://blog.sudobits.com/2013/01/07/how-to-deploy-rails-application-to-vps/