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:
- Install Ruby VM
- Install Rails
gem install rails -v '= 2.3.5' --include-dependencies - Install any other dependencies your application requires
- Install Sql Server adapter
gem install activerecord-sqlserver-adapter --version 2.3.5 - Install ruby-odbc
- Download ruby-odbc
- Copy the zip's content to ${RUBY_INSTALLATION_DIR}\lib\ruby\site_ruby\1.8\i386-msvcrt
- 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) - Create a System DSN using your specific database connection properties
- Open the command prompt and go to the Rails application root folder
- Create and initialize your database
- rake db:create RAILS_ENV=production
- rake db:migrate RAILS_ENV=production
- rake db:seed RAILS_ENV=production
- 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) - 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.) - 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
- Rule 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.
- Download this win32 services gem and install it.
- Download this mongrel-service gem and install it.
- 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.. - Launch the Window Services console from Control Panel. Change the startup type of your mongrel services to Automatic and start each of them.
- Open a browser and test your application
Finally, some articles you might find useful:
