deploy ruby on rails on windows 2008 server and iis 7.0

Deploying Ruby On Rails in a Windows environment can be very painful. I couldn't find any blog which really helped me, so I decided to summarize all the necessary steps I followed to successfully deploy a Rails application in a Windows 2008 server from scratch. I won't give much explanation on each step, so if you like to know more about it, at the end of this post you'll find a list of articles I found useful.

**The environment: **

  • Windows 2008 SP2 x64
  • SQL Server 2005
  • IIS 7.0
  • Ruby 1.8.7
  • Ruby on Rails 2.3.5
  • Mongrel 1.1.5

Steps:

  1. Install Ruby VM
  2. Install Rails: gem install rails -v '= 2.3.5' --include-dependencies
  3. Install any other dependencies your application requires
  4. Install SQL Server adapter: gem install activerecord-sqlserver-adapter --version 2.3.5
  5. Install ruby-odbc
    a. Download ruby-odbc
    b. Copy the zip's content to ${RUBY_INSTALLATION_DIR}\lib\ruby\site_ruby\1.8\i386-msvcrt
  6. Open the ODBC Data Source Administrator with the command C:\Windows>SysWOW64\odbcad32.exe (make sure you use this command instead of using the regular access from the control panel)
  7. Create a System DSN using your specific database connection properties
  8. Open the command prompt and go to the Rails application root folder
  9. Create and initialize your database:
  • rake db:create RAILS_ENV=production
  • rake db:migrate RAILS_ENV=production
  • rake db:seed RAILS_ENV=production
  1. Install IIS Application Request Routing and URL Rewrite extensions
    Edit the hosts file located at C:\Windows\System32\drivers\etc\hosts and add the following line 127.0.0.1 localhost localhost-1 localhost-2 (add as many localhost-x hostnames as mongrel services you're planning to setup)
  2. Open IIS Manager and create a new farm. Add one server for each of the mongrel services you're planning to setup. For each server use a different address (i.e. localhost-1, localhost-2, etc.) and a different port number (i.e. 3000, 3001, etc.)
  3. Edit URL Rewrite rules and add the following rules
    Rule 1
  • Pattern: ^$
  • Action: Route to Server Farm
  • Path: /main/index
  • Check stop processing subsequent rules

Rule 2

  • Pattern:([.]+)$
  • Action: Route to Server Farm
  • Path: /{R:1}
  • Do not check stop processing subsequent rules
  1. In the IIS Manager create a new Web Site and in the Path box, type or browse to the directory that contains your Rails public folder.
  2. Download this win32 services gem and install it.
  3. Download this mongrel-service gem and install it.
  4. Setup as many mongrel services as you need
mongrel_rails service::install -N my-app-node-1 -e production -p 3000
mongrel_rails service::install -N my-app-node-2 -e production -p 3001
etc..
  1. Launch the Window Services console from Control Panel. Change the startup type of your mongrel services to Automatic and start each of them.

  2. Open a browser and test your application

Finally, some articles you might find useful:

ODBC binding for Ruby

Create a 32bit DSN on a 64bit operating system

Ruby on Rails in IIS70 with url rewriter

Define and configure an application request routing server farm

Creating rewrite rules for the url rewrite module

10 steps to get Ruby on Rails running on Windows with IIS FastCGI