bantic (owner)

Fork Of

Revisions

gist: 121020 Download_button fork
public
Public Clone URL: git://gist.github.com/121020.git
Embed All Files: show embed
Text only #
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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
Deploying a Rails App with EC2 + S3 + Ubuntu
============================================
 
Create EC2 Instance
-------------------
 
    create new instance ami-bf5eb9d6 [http://alestic.com/](http://alestic.com/)
    create new elastic ip
    attach elastic ip to instance
    point dns to elastic ip
    set the `:host` in `config/deploy.rb` to the new elastic ip
 
 
Create S3 Buckets
-----------------
 
    for production: projectname, projectname_backup
    for development: projectname_development, projectname_development_backup
 
 
Connect to Server
-----------------
 
    create local ~/.ssh/projectname_production_root file with private rsa ssh key, chmod 600
    ssh in as root such as ssh root@1.2.3.4 -i ~/.ssh/projectname_production_root
 
 
Install Packages
----------------
 
First update existing packages:
 
    # apt-get update
    # apt-get upgrade
 
Then install new packages:
 
    # apt-get install apache2
    # apt-get install apache2-prefork-dev
    # apt-get install build-essential
    # apt-get install exim4
    # apt-get install git-core
    # apt-get install imagemagick
    # apt-get install irb
    # apt-get install libmysqlclient15-dev
    # apt-get install libyaml-ruby
    # apt-get install libzlib-ruby
    # apt-get install mysql-server
    # apt-get install rdoc
    # apt-get install ruby
    # apt-get install ruby1.8-dev
    # apt-get install rubygems
    # apt-get install sqlite3
 
When prompted set the mysql-server password.
 
 
Install Rubygems
----------------
 
First install Rubygems itself:
 
    # gem install rubygems-update
    # gem update --system
 
Something is messed up with this version of rubygems so we have to do something ghetto:
 
    # vi /usr/bin/gem
    After the line:
    require 'rubygems'
    Add:
    require 'rubygems/gem_runner'
 
Then install the individual gems:
 
    # gem install daemons
    # gem install fastthread
    # gem install hpricot
    # gem install json
    # gem install mime-types
    # gem install mysql
    # gem install open4
    # gem install passenger
    # gem install rack
    # gem install rake
    # gem install right_aws
    # gem install ruby-mp3info
    # gem install sqlite3-ruby
 
 
Configure Exim4
---------------
 
Run the configurator:
 
    # dpkg-reconfigure exim4-config
 
And enter these values as prompted:
 
- internet site, sent directly via smtp
- projectname.com
- 127.0.0.1
- other destinations: [blank]
- relay: [blank]
- relay: [blank]
- dns minimal: no
- delivery method: mbox
- small files: no
- root: root
 
 
Configure MySQL
---------------
 
    # mysqladmin -u root -p create projectname_production
    # mysql -u root -p
 
    mysql> CREATE USER 'projectname_prod'@'localhost' IDENTIFIED BY 'password';
    mysql> FLUSH PRIVILEGES;
    mysql> CREATE DATABASE projectname_production DEFAULT CHARACTER SET utf8 DEFAULT COLLATE utf8_general_ci;
    mysql> GRANT ALL PRIVILEGES ON projectname_production.* TO 'projectname_prod'@'localhost' IDENTIFIED BY 'password' WITH GRANT OPTION;
 
 
Configure Apache and Phusion Passenger
--------------------------------------
 
Run the Passenger configurator:
 
    # passenger-install-apache2-module
 
Edit Apache configs:
 
    # cd /etc/apache2/
    # a2enmod deflate
    # vi conf.d/projectname
        NameVirtualHost *
        LoadModule passenger_module /usr/lib/ruby/gems/1.8/gems/passenger-2.0.6/ext/apache2/mod_passenger.so
        PassengerRoot /usr/lib/ruby/gems/1.8/gems/passenger-2.0.6
        PassengerRuby /usr/bin/ruby1.8
        PassengerUseGlobalQueue on
        PassengerMaxPoolSize 25
    # vi sites-available/placeholder
        <VirtualHost *>
          ServerName projectname.com
          DocumentRoot /home/projectname/static_page
        </VirtualHost>
    # vi sites-available/projectname
        <VirtualHost *>
          ServerName projectname.com
          DocumentRoot /home/projectname/projectname/current/public
          AddOutputFilterByType DEFLATE text/html text/plain text/xml text/javascript text/css application/x-javascript
          BrowserMatch ^Mozilla/4 gzip-only-text/html
          BrowserMatch ^Mozilla/4\.0[678] no-gzip
          BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
          CustomLog /var/log/apache2/projectname.com-access.log combined
          ErrorLog /var/log/apache2/projectname.com-error.log
          LogLevel warn
        </VirtualHost>
    # a2dissite default
    # a2ensite projectname
    # apache2ctl restart
 
 
Setup Deployment Credentials
----------------------------
 
Create and change to the UNIX `projectname` user:
 
    # adduser projectname password
    TODO: disable projectname user password
    # su - projectname
 
Create an SSH key:
 
    $ ssh-keygen -t dsa
    [no passphrase]
 
Add as a deploy key on github:
 
    $ cat .ssh/id_dsa.pub
    copy + paste this into a new deploy key at https://github.com/username/projectname/edit
 
* ensure that `ssh_options[:keys]` in `config/deploy.rb` contains the correct key name
* add remote projectname user's public ssh key to locally:
* $ vi ~/.ssh/projectname_production_projectname.pub
* add local public ssh key to remote ~projectname/.ssh/authorized_keys
 
 
Initialize and Configure the Application
----------------------------------------
 
Locally, init the remote deploy:
 
    $ cap deploy:cold
 
Create the remote rails database config file:
 
    $ vi ~projectname/projectname/shared/database.yml
        production:
          adapter: mysql
          host: localhost
          username: projectname_prod
          password: password
          database: projectname_production
          timeout: 5000
          encoding: UTF8
          socket: /var/run/mysqld/mysqld.sock
 
Load the initial schema:
 
    $ cd ~projectname/projectname/current
    $ RAILS_ENV=production rake db:schema:load
 
 
Deploy the Application
----------------------
 
At this point, ensure that all code (including the updated `config/deploy.rb`) is checked in locally, merged onto the `deploy` branch, and pushed to github.
 
Then, locally:
 
    $ cap deploy
 
Confirm that the app is running at [http://projectname.com](http://projectname.com).
 
 
TODO
----
 
* fix cache thing
* cap deploy todos
* cap to after deploy:cold create:
  * mkdir ~muxtape/muxtape/releases
  * mkdir ~muxtape/muxtape/shared/log
  * also pids + system dirs