Recently I took a journey into IronRuby.Rack and found that it's not quite ready for prime time yet. However, what does work is URL rewriting and FastCGI on IIS7. For the record, if you can avoid doing this, please do!
Props to these references for getting me started.
- http://blogs.msdn.com/dgorti/archive/2009/06/17/ruby-on-rails-with-iis-7-reloaded.aspx
- http://ruslany.net/2008/08/ruby-on-rails-in-iis-70-with-url-rewriter/
- http://mvolo.com/blogs/serverside/archive/2007/02/18/10-steps-to-get-Ruby-on-Rails-running-on-Windows-with-IIS-FastCGI.aspx
- http://hotgazpacho.org/2009/02/rails-230-iis7-fastcgi-rails-on-windows-ftw/
Here is what -I- did
Enable FastCGI support in IIS7
http://learn.iis.net/page.aspx/246/using-fastcgi-to-host-php-applications-on-iis-70/#EnableFastCGIInstall URL Rewrite module
Using the Web Platform Installer I installed the URLRewrite module.Install Ruby
Obtain the Ruby MSI Installer for windows and run it keeping all the defaults (ex. Install location => C:\Ruby)Update Rubygems
Open a terminal window and run the following:gem update --system
Install Rails
gem install rails --include-dependencies
Install Sqlite3
NOTE: This approach seems to work fine for 32 bit Windows installs, not for 64 bit.To get started grab sqlitedll-3_6_23.zip from the sqllite website.
Expand the zip and copy both files (sqlite3.def, sqlite3.dll) to C:\Ruby\bin
Then install the sqlite gem by running:
gem install sqlite3-ruby --include-dependenciesFor additional information on this step you can refer to this post.
Verify the step worked by running
gem list
Put a Rails app on your machine
At this point, we are getting close. You can either create a brand new Rails app by runningrails myapp rake db:migrateOr copy an existing Rails app to your machine.
Setup up web site in IIS7
Open the IIS management application.Add a new website and point it to your Rails sites public folder.
Click on the website and you should see a "Handler Mappings" option. Click it and then select "Add Module Mapping ...".
I also added an entry in my hosts file for my Rails app.
127.0.0.1 myapp
Add URL Rewriting Rules
In the same section as the "Handler Mappings", there should be a "URL Rewrite" option, open it.Select "Import Rules ..." and paste the following in
# Redirect all requests not available on the filesystem to Rails RewriteEngine On RewriteRule ^$ index.html [QSA] RewriteRule ^([^.]+)$ $1.html [QSA] RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^(.*)$ dispatch.fcgi [QSA,L]It should show you the rules in the TreeView with green checkmarks. If so, then save and apply those rules.
Create your dispatch.fcgi
I used this simple dispatcher for my Rails app, use it to get you started.require File.dirname(__FILE__) + "/../config/environment" require 'fcgi_handler' RailsFCGIHandler.process! nil, 10Save it as dispatch.fcgi in your Rails apps public folder.
Permissions!!
If you were to view the site now, you would probably be met with a 500 error. To resolve this, add NETWORK SERVICE to your Rails app folder and give them Full Control.This part of the process is a pain and I'm sure it's slightly different for everyone depending on their server config and version of Windows.If NETWORK SERVICE does not solve it, verify that
it is a permissions problem by allowing Everyone access to the Rails app. If that allows you to load the site, then REMOVE Everyone and try to narrow it down to the required account.
Reset IIS
64 bit
If you are running on 64 bit, you can enable 32-bit applications in the application pool for your site under Advanced Settings.My problems
SQLite3 gave me all kinds of trouble. I finally abandoned it and went right to MySQL. Here is the error I was seeing in my log:SQLite3 problem /!\ FAILSAFE /!\ Wed Mar 17 09:25:47 -0400 2010 Status: 500 Internal Server Error 127: The specified procedure could not be found. - Init_sqlite3 ./sqlite3.dllSo I downloaded and installed MySql and selected mysql-essential-5.1.45-winx64.msi
I then changed my database.yml to use mysql instead of sqlite3 and installed the mysql gem
gem install mysqlbut once again, 32 bit caused a problem and I had to download another dll and copy it to C:\Ruby\bin For instructions on where to get the dll look here.