The ELC Community Blog
A knowledge exchange on Ruby on Rails and Agile Development
Ruby on Rails on EC2
by Ryan Garver on November 11, 2006
Here is my process for installing a fully featured Ruby on Rails EC2 image. This includes Apache 2.2, MySQL 5, and Mongrel installed and with a baseline configuration. Ideally this will be the snapshot that we store to S3 since we want to use this for multiple web servers if possible. Any further customization we can do at boot time or at deployment. Some of this is based off of the linux weblog's process. I should also mention that it would be a good idea to run all of this under a screen session so that you can come back to some of the longer operations if your ssh connection drops (I left it alone for too long on a few occasions).
Prerequisites
This process expects a very basic Fedora Core 5 installation and isn't necessarily isolated to EC2. I would recommend following my previous article to get an image up to the right versions. This should work if you come from that procedure.
Setup a build environment
Coming from the base Fedora Core 4 and upgrading to 5 (as described in the previous post) gives us a good base system; however, it is not setup with any developer tools. Namely a compiler and build tools. Ruby, and more specifically some of the rubygems that we will be installing, need these tool to build the external library and language hooks.
yum install -y gcc gcc-c++ automake
Apache 2.2
Next is apache. I'll leave the actual configuration of apache as an exercise for the reader and possibly a future post. We need to make sure that we are grabbing Apache 2.2 (which is the default for FC5) because most configurations of Mongrel with Apache as a proxy require mod_proxy_balancer. We're also going to install mod_ssl for https support. If you won't be using this feel free to leave it off.
yum install -y httpd mod_ssl
MySQL 5
What fun is a web site without a database? We are using MySQL 5 as our preferred database. There are some RPMs that we are installing here that may appear optional; however, many of these are needed for later in this process when we install the ruby bindings.
yum install -y mysql mysql-server mysql-devel mysqlclient14 mysqlclient14-devel
Ruby
And now, of course, ruby. These steps get the baseline ruby install in place and take advantage of a few RPMs which won't install easily as gems. This also gets rubygems up and going for the next step
yum install -y ruby ruby-libs ruby-mode ruby-rdoc ruby-irb ruby-ri ruby-docs ruby-devel ruby-mysql wget http://rubyforge.org/frs/download.php/11289/rubygems-0.9.0.tgz tar zxf rubygems-0.9.0.tgz cd rubygems-0.9.0 ruby setup.rb
Rails and Mongrel
And now for what we've all been waiting for rails. We're also going to install mongrel here. Now-a-days (November 2006) mongrel appears to be the preferred method of running rails. In fact in the newest edge rails versions script/server will use mongrel if it detects that it is installed. In my opinion mongrel is a great application server and because it has a lot of interest from the rails groupies it is really easy to manage with rails as well.
gem install -y rails mongrel mongrel_cluster
Fun Ruby extras!
yum install -y ImageMagick-devel ImageMagick-c++-devel libpng-devel freetype-devel gem install -y rmagick daemons json tzinfo mime-types capistrano capistrano-ext
...and don't forget
When I first built this image I forgot this step and ended up needing to re-image the instance. That ends up being an extra 45 minutes that went to waste; I don't recommend it.
yum install -y subversionOK, enjoy! I might add another follow on to this two part series on how to get Capistrano working nicely. Currently I have some general purpose recipes that I'm putting together so stay tuned.
Comments