Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
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_backup
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/ ubuntu@ELASTIC_IP:/home/ubuntu/.ssh/ (from local)
6 sudo mv ~/.ssh/ /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
-- 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/
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>
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
Enable site
$ sudo a2ensite
Setup Deployment Credentials
1 Change to application user
2 $ ssh-keygen -t dsa
3 copy to github repo > Admin > Deploy keys
Set up environment variables if necessary
$ cat .ssh/environment
make sure /etc/ssh/sshd_config contains:
PermitUserEnvironment yes
Might have to restart ssh with sudo /etc/init.d/ssh restart
Create the following directories if they don't exist:
MySQL setup
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment