A couple of weeks ago there was a post on the FiveRuns blog about automatically installing the Rails stack on an Ubuntu 8.04 VPS.
I prefer to use Passenger and Ruby Enterprise Edition when running my Rails app, so inspired by the FiveRuns script I wrote my own version – here is the gist on github.
#!/bin/bash
# Inspired by http://blog.fiveruns.com/2008/9/24/rails-automation-at-slicehost
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
RUBYGEMS="rubygems-1.3.0"
wget http://rubyforge.org/frs/download.php/43985/$RUBYGEMS.tgz
tar xzf $RUBYGEMS.tgz
cd $RUBYGEMS
ruby setup.rb
cd ..
# Install Ruby Enterprise Edition
wget http://rubyforge.org/frs/download.php/41040/ruby-enterprise-1.8.6-20080810.tar.gz
tar xvzf ruby-enterprise-1.8.6-20080810.tar.gz
yes '' | ./ruby-enterprise-1.8.6-20080810/installer
# Install Passenger
/usr/bin/gem1.8 install -v=2.0.3 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 --no-rdoc --no-ri
cd /var/www
rails -d mysql hello
cd hello
./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 <> /etc/apache2/mods-available/passenger.conf <<-EOF
PassengerRoot /usr/lib/ruby/gems/1.8/gems/passenger-2.0.3
PassengerRuby /opt/ruby-enterprise-1.8.6-20080810/bin/ruby
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/hello <<-EOF
ServerName www.yourhost.com
DocumentRoot /var/www/hello/public
EOF
a2ensite hello
# That's it!
reboot
The script assumes that you have ssh access as root to a clean Ubuntu 8.04 install.
The script will install
- Ruby 1.8.6
- RubyGems 1.3.0
- Passenger 2.0.3
- Ruby Enterprise Edition 20080810
- Apache 2.2.8
- MySQL 5.0.51a
- A sample Rails app
Note that the Passenger installer will install the latest Rails (2.1.1) and a bunch of other useful gems.
Assuming that your server IP address is 192.168.185.128 you can run it like this:
ssh root@192.168.185.128 "wget -O - http://gist.github.com/raw/16225/a6a16b3a38cd3486679b96fa0f3446e58f3b8423 | sed -e s/$'\r'//g > install.sh; /bin/bash install.sh; rm install.sh"
Sit back and enjoy – in less than ten minutes you will have the full Rails stack and a sample Rails app running. Take a look at it on http://192.168.185.128/welcome/hello
Hi Jørgen,
Very cool Passenger and Ruby Enterprise updates! I made a few enhancements to the original script at: http://blog.fiveruns.com/2008/10/19/automatic-production-rails to include Capisrano and some other services.
Best,
Mark
Any chance a Red Hat flavored script could be whipped up? I’m having troubles getting everything up and running.
yes ” | ./ruby-enterprise-1.8.6-20080810/installer
Gives me just a new line awaiting a response (> ). In other words, it thinks the command isn’t completed, I believe.
Do you know the problem/solution?
Thanks, appreciate it.
@Kyle
What happens if you run the ./ruby-enterprise-1.8.6-20080810/installer command by hand? Does it give you any kind of error?
Nope, same thing. Do I need to install the ‘yes’ command, or something?
Or is there another way to get the same result?
Again, thanks.
I just took out the ‘yes ” |’ part and put ‘./ruby-enterprise-1.8.6-20080810/installer’, which seemed to work.
Oh god, I just wasn’t looking from the github page. All apologies.
Sorry to keep bothering you, but if I wanted to use postgres instead of mysql, what commands would I use instead? I tried various things, but of course errors arise.