deploy ruby on rails on windows 2008 server and iis 7.0
Deploying Ruby On Rails in a Windows environment can be very painful. That's why Emilio decided to summarize all the necessary steps and share them with us!
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
a. Download ruby-odbc
b. 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 atC:\Windows\System32\drivers\etc\hosts
and add the following line127.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
- 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:
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