Skip to content

Instantly share code, notes, and snippets.

@juliamae
Forked from luke0x/gist:115795
Created December 23, 2010 18:01
Show Gist options
  • Save juliamae/753311 to your computer and use it in GitHub Desktop.
Save juliamae/753311 to your computer and use it in GitHub Desktop.
Deploying a Rails 3 App with EC2 + S3 + Ubuntu + Capistrano + Passenger
Deploying a Rails 3 App with EC2 + S3 + Ubuntu + Capistrano + Passenger
=======================================================================
EC2 Setup
---------
1 Launch New ec2 instance - ami-1634de7f
2 Create elastic IP [ELASTIC_IP] and associate it with instance
3 go to domain registrar DNS settings, @ and www to ELASTIC_IP
4 set the `:host` in `config/deploy.rb` to ELASTIC_IP
S3 Setup
--------
1 create buckets:
- application.com
- application.com_backup
etc
Connect to server & make user to run app
----------------------------------------
1 ssh-keygen, choose special name
2 ssh ubuntu@ELASTIC_IP -i ~/.ec2/applicationkey.pem
3 sudo su; useradd -d /home/application -m application; passwd application
4 as ubuntu or root, sudo visudo, arrow down to bottom and application ALL=(ALL) NOPASSWD:ALL
5 scp -i ~/.ec2/applicationkey.pem ~/.ssh/id_rsa_application.pub ubuntu@ELASTIC_IP:/home/ubuntu/.ssh/ (from local)
6 sudo mv ~/.ssh/id_rsa_application.pub /home/application/.ssh/authorized_keys
7 sudo chmod 600 /home/application/.ssh/authorized_keys
8 sudo chown application /home/application/.ssh/authorized_keys
9 now you can ssh application@ELASTIC_IP -i ~/.ssh/id_rsa_application yay!
10 do above, then mkdir deploy
Install Shit
-----------
sudo apt-get update
sudo apt-get upgrade
sudo apt-get install apache2
sudo apt-get install apache2-prefork-dev
sudo apt-get install exim4
sudo apt-get install git-core
sudo apt-get install irb
sudo apt-get install rdoc
sudo apt-get install ruby
sudo apt-get install ruby1.8-dev
sudo apt-get install rubygems
sudo apt-get install mysql
sudo apt-get install libopenssl-ruby
gem install rubygems-update
gem install passenger
gem install rake
gem install bundler (might need to manually build rubygems if version is not up to date)
Configure Exim4
---------------
1 dpkg-reconfigure exim4-config
-- internet site, sent directly via smtp
-- application.com
-- 127.0.0.1
-- other destinations: [blank]
-- relay: [blank]
-- relay: [blank]
-- dns minimal: no
-- delivery method: mbox
-- small files: no
-- root: root
Setup Passenger
---------------
1 passenger-install-apache2-module
2 $ cd /etc/apache2/; a2enmod deflate; vi conf.d/passenger
## passenger stuff might change with different version ##
LoadModule passenger_module /var/lib/gems/1.8/gems/passenger-3.0.0/ext/apache2/mod_passenger.so
PassengerRoot /var/lib/gems/1.8/gems/passenger-3.0.0
PassengerRuby /usr/bin/ruby1.8
Setup Apache VHost
------------------
$ vi sites-available/application
<VirtualHost *:80>
ServerName application.com
DocumentRoot /home/application/deploy/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
SetEnv ENV_YOU_WANT_TO_SET this_is_the_val # optional
<Directory /somewhere/public>
AllowOverride all
Options -MultiViews
</Directory>
</VirtualHost>
Enable site
-----------
$ sudo a2ensite application.com
Setup Deployment Credentials
----------------------------
1 Change to application user
2 $ ssh-keygen -t dsa
3 copy id_dsa.pub to github repo > Admin > Deploy keys
Set up environment variables if necessary
-----------------------------------------
$ cat .ssh/environment
AMAZON_ACCESS_KEY_ID='KEYYY'
AMAZON_SECRET_ACCESS_KEY='SECRETTT'
make sure /etc/ssh/sshd_config contains:
PermitUserEnvironment yes
Might have to restart ssh with sudo /etc/init.d/ssh restart
Deploy!
-------
Create the following directories if they don't exist:
/home/application/deploy/releases
/home/application/shared/log
TODO:
MySQL setup
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment