Skip to content

Instantly share code, notes, and snippets.

@weepy
Created August 17, 2009 14:30
Show Gist options
  • Save weepy/169147 to your computer and use it in GitHub Desktop.
Save weepy/169147 to your computer and use it in GitHub Desktop.
#!/bin/bash
# Inspired by http://blog.fiveruns.com/2008/9/24/rails-automation-at-slicehost
RUBYGEMS="rubygems-1.3.5"
RUBYGEMS_URL="http://rubyforge.org/frs/download.php/60718/$RUBYGEMS.tgz"
PASSENGER_VERSION="2.2.5"
THIS_HOST="www.yourhost.com"
APP_NAME="my_new_app"
RUBY_ENTERPRISE="ruby-enterprise-1.8.7-20090928"
RUBY_ENTERPRISE_URL="http://rubyforge.org/frs/download.php/64475/$RUBY_ENTERPRISE.tar.gz"
apt-get update
apt-get upgrade -y
apt-get -y install build-essential libssl-dev libreadline5-dev zlib1g-dev
apt-get -y install mysql-server libmysqlclient15-dev mysql-client
apt-get -y install ruby ruby1.8-dev irb ri rdoc libopenssl-ruby1.8
apt-get -y install git-core
wget $RUBYGEMS_URL
tar xzf $RUBYGEMS.tgz
cd $RUBYGEMS
ruby setup.rb
cd ..
/usr/bin/gem1.8 update --system
# Install Ruby Enterprise Edition
wget $RUBY_ENTERPRISE_URL
tar xvzf $RUBY_ENTERPRISE.tar.gz
yes '' | ./$RUBY_ENTERPRISE/installer
# Install Mysql Gem
/usr/bin/gem1.8 install mysql --no-rdoc --no-ri
# Install Passenger
/usr/bin/gem1.8 install -v=$PASSENGER_VERSION passenger --no-rdoc --no-ri
apt-get -y install apache2-mpm-prefork apache2-prefork-dev
yes '' | passenger-install-apache2-module
# Create sample Rails app
/usr/bin/gem1.8 install rails thin mongrel --no-rdoc --no-ri
cd /var/www
rails -d mysql $APP_NAME
cd $APP_NAME
./script/generate controller welcome hello
echo "Hello World" > app/views/welcome/hello.html.erb
rake db:create RAILS_ENV=production
# Create the Apache2 Passenger module files
cat >> /etc/apache2/mods-available/passenger.load <<-EOF
LoadModule passenger_module /usr/lib/ruby/gems/1.8/gems/passenger-$PASSENGER_VERSION/ext/apache2/mod_passenger.so
EOF
cat >> /etc/apache2/mods-available/passenger.conf <<-EOF
<IfModule passenger_module>
PassengerRoot /usr/lib/ruby/gems/1.8/gems/passenger-$PASSENGER_VERSION
PassengerRuby /opt/$RUBY_ENTERPRISE/bin/ruby
</IfModule>
EOF
a2enmod passenger
# Create a site file for the sample Rails app
IP_ADDRESS=`ifconfig eth0 | sed -n 's/.*dr:\(.*\) Bc.*/\1/p'`
cat >> /etc/apache2/sites-available/$APP_NAME <<-EOF
<VirtualHost $IP_ADDRESS:80>
ServerName $THIS_HOST
DocumentRoot /var/www/$APP_NAME/public
</VirtualHost>
EOF
a2ensite $APP_NAME
# That's it!
reboot
# and visit hello.myapp.com/welcome/hello
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment