Recently, we had an encounter with Rails 3 on EC2 for one of our esteemed clients. The client wanted to host his application on Amazon EC2(and rightly so given that its such an amazing infrastructure at such an affordable cost). After searching the public AMIs, we could not come out with an AMI that had all our requirements satisfied(Rails 3, Postgres, phusion passenger). This lead us to trigger our sys admins to prepare the bare minimum EC2 AMI with the required development stack. We documented the steps if they can be helpful to someone. 1. Choose a bare minimum AMI, we chose centos 5.5 based 64 bit AMI. 2. download the keypair and log into your server with ssh. 3. You need to be root to perform the following steps, so if you log in with ec2-user type in the following command to become the root user:
sudo su -
Install Ruby and Rails 3:
- The amazon machine instance(AMI) comes with ruby 1.8.7 installed as of today.
- Rails 3 needs ruby 1.9+ to work.
- Ruby 1.9.1 is a buggy version so we will go ahead and install ruby 1.9.2
- We could not find rpms of ruby 1.9.2 on centos repos or even on rpmforge, so we had to go ahead and install ruby from source.
- Download ruby sources from http://www.ruby-lang.org/en/downloads
- wget ftp://ftp.ruby-lang.org//pub/ruby/1.9/ruby-1.9.2-p136.tar.gz
- unpack it !!
tar xzvf ruby-1.9.2-p136.tar.gz
- Install development tools.
- yum groupinstall ‘Development Tools’
- yum install readline-devel
- Move to ruby sources and compile
- Sit back and relax. Ruby will take some time to compile. It took about 7-9 minutes for us on EC2 micro instance
- After you are done with ruby install. Install rails.
gem install rails
cd ruby-1.9.2-p136 ./configure make && make install
Install Apache and Passenger
- Install Apache 2.
yum install httpd
yum install httpd-devel
- Install passenger.
- In case you get the following error,
To install OpenSSL support for Ruby:
Please (re)install Ruby with OpenSSL support by downloading it fromhttp://www.ruby-lang.org/. Go to ruby source directory and install openssl extension.
LoadModule passenger_module /usr/local/lib/ruby/gems/1.9.1/gems/passenger-3.0.2/ext/apache2/mod_passenger.so PassengerRoot /usr/local/lib/ruby/gems/1.9.1/gems/passenger-3.0.2 PassengerRuby /usr/local/bin/ruby LoadModule passenger_module /usr/local/lib/ruby/gems/1.9.1/gems/passenger-3.0.2/ext/apache2/mod_passenger.so PassengerRoot /usr/local/lib/ruby/gems/1.9.1/gems/passenger-3.0.2 PassengerRuby /usr/local/bin/ruby
<VirtualHost *:80> ServerName www.yourhost.com DocumentRoot /somewhere/public # <-- be sure to point to 'public'! <Directory /somewhere/public> AllowOverride all # <-- relax Apache security settings Options -MultiViews # <-- MultiViews must be turned off </Directory> </VirtualHost>
yum install postgres