Friday, July 31, 2009

Ruby 1.9 Ubuntu Amazon AMI

Amazon's EC2 allows you to quickly fire up, scale out, and tear down servers at will. It's slick. It's dependable. It's game changing (we spent an entire day testing on 2 servers for under $4).

With that said, we're not huge fans of loaded AMI's. They have the potential for unnecessary maintenance, upgrades, etc. Doesn't that take away from the cleanliness that EC2 offers? Instead, use a base bundle, and Capistrano away. I'll post a follow-up post on that soon.

We're also Ruby 1.9 fans, so we took Ruby 1.9.1p129, installed it into an Alestic Ubuntu Jaunty base AMI, and rebundled it. It took a bit of work since Amazon's tools, AMI's, and Ruby 1.9 aren't totally in sync, but with a bit of work, you can get a clean, production-ready AMI with Ruby 1.9.

Feel free to use ours. It's located in the public AMI list:

appoxy-amis/ubuntu-9.04-jaunty-ruby1.9-base-20090731.manifest.xml
AMI ID: ami-51769738

Enjoy,
Chad


Saturday, July 18, 2009

Installing Ruby 1.9, Apache2, Rails, and Phusion Passenger on new Ubuntu EC2 Instance









Here's the step by step for getting Ruby on Rails running on a sparkling fresh new Amazon EC2 Instance.

1) Launch EC2 Instance

I won't explain this, but pick the latest Ubuntu AMI. The rest of this assumes you're ssh'd into the new isntance.

2) Install Ruby 1.9
  • apt-get update
  • apt-get upgrade
  • apt-get install zlibc zlib-bin zlib1g zlib1g-dbg zlib1g-dev libopenssl-ruby1.9 libssl-dev subversion git-core apache2 apache2-prefork-dev libapr1-dev
  • Install ruby
    • tar -zxvf ruby1.9....tgz
    • cd ruby1.9....
    • ./configure && make && make install
  • ruby -v
    • to check that installed properly
  • cd ext/openssl
  • ruby extconf.rb && make && make install
    • This installs openssl support for ruby

3) Now get Rails up and running

  • gem sources -a http://gems.github.com
  • gem install rails sqlite3-ruby passenger
  • passenger-install-apache2-module
    • follow instructions
    • it will give you a few lines you have to add to: /etc/apache2/apache2.conf (bottom is fine)
  • Get your Rails app on server somewhere
    • If you have an existing app, upload it to the server (eg: /home/myapp would work fine)
    • Now if you don't have a rails app ready to go, lets quickly make one
      • cd /home
      • rails first_rails
  • nano -w /etc/apache2/sites-available/first_rails
  • Assuming you have some.domain.com pointed to the server (this can replace the Apache default site as well):



    • ServerName www.yourhost.com # delete this line if replacing root
      DocumentRoot /home/rails/public
      Allow from all
      # RailsEnv development
      RailsDefaultUser root


  • a2ensite first_rails
    • adds site to sites-enabled
  • /etc/init.d/apache2 reload

That's it.

If you want your app under a sub directory of a different virtual host, see the instructions here:http://www.modrails.com/documentation/Users%20guide.html#_deploying_a_ruby_on_rails_application

Troubleshooting
  • If you get: no such file to load rbconfig.rb
    • be sure all 1.8 stuff is removed
      • apt-get remove libruby1.8 rubygems

And lastly, get the latest awesome gems for web development:

gem install uuidtools appoxy-aws right_http_connection appoxy-simple_record appoxy-local_cache quetzall-cloud_cache

And you should probably setup logrotate to keep your log files under control, but that will come in another post.

Sunday, July 12, 2009

Installing Ruby 1.9 on Windows

As you may already know, Ruby and Windows aren't the best of friends, but you can make it work. Here's how to quickly and easily get Ruby 1.9 up and running on windows.
  1. If you already have Ruby 1.8 installed, make a backup copy of c:\ruby
  2. Download pre-built Ruby 1.9 package for windows here: http://rubyinstaller.org/downloads/
  3. Unzip it into c:\ruby
  4. If you already had Ruby 1.8 installed, you are good to go! If not, add c:\ruby\bin to your PATH environment variable.
Run ruby -v at the command line to check your version.