Really sorry mate, was in a training course all this week. Tim, yeah
played a fair bit with JRuby, I like it a lot and I think the
deployment options are pretty sweet as well. Def take a look at it if
you can Arunan. If you want to stick with MRI though, there's much
better deployment options than going with IIS, kick your team in the
nuts mate..

Not sure if you still want this, but steer clear of that roriis link
you put up. Just as a rule of thumb, NEVER EVER install an exe that
attempts to patch your gems!

Anywho, here's my notes, I put em together a while back so they apply
to a rails 2.3.5 app.. hope they help

-------------------------------------------------------------------------------
IIS Deployment notes


This guide assumes you've already got IIS installed.

My Env
IIS 5.1
Ruby 1.8.6
Gem 1.3.5
Rails 2.3.5

There's 2 ways you can do this, you can either set up IIS to proxy to
a mongrel_service instance of your rails app or you can use fcgi to
serve up requests. This guide will explain the .fcgi method

Rails expects pretty looking URL's to handle requests, but IIS
requires the path to your dispatch.fcgi file for it to be able to
serve up the request, so you need an equivalent of apache's
mod_rewrite module to step in and fix up the URL so that both are
happy.

Here's how the requests need to come in for everything to work:

User makes request to  : http://localhost/controller/action?var1=foo&var2=bar
Rewrite Mod changes to : 
http://localhost/dispatch.fcgi?opnq=/controller/action?var1=foo&var2=bar
IIS accepts and serves up request to dispatch.fcgi
dispatch.fcgi spins up ruby instance of your app
Rails app receives and needs to change request back into original form
Rails turns request back into : 
http://localhost/controller/action?var1=foo&var2=bar


1. In your rails app make sure there is not a file in your public
directory named .htaccess <-- rename it to anything else,
apache.htaccess for example


2. In your public directory there's probably already a dispatch.fcgi
file, if not create one.

#{RAILS_ROOT}/public/dispatch.fcgi

require File.dirname(__FILE__) + "/../config/environment"
require 'fcgi_handler'

RailsFCGIHandler.process!


3. Open a command prompt, cd into your rails app's public directory
and run: ruby dispatch.fcgi
If it outputs: unknown listenType (0)
That's good, that's what you want. If it spits out an error you'll
need to find out what's causing it and fix it.


4. IIS 5 & 6 don't support fcgi by default so you have to install
support for the fcgi protocol for IIS, there's an update for the IIS7
version on this page as well:
http://www.iis.net/download/fastcgi

The fcgi installer will install a few files including the following 2:

C:\WINDOWS\system32\inetsrv\fcgiext.ini
C:\WINDOWS\system32\inetsrv\fcgiext.dll


5. Open fcgiext.ini in a text editor, scroll to the bottom and add the
following, replace the 'Arguments' and 'ExePath' paths with your own:
The 'MaxInstances' argument specifies the maximum amount of ruby
processes that can fire up to handle requests.

#C:\WINDOWS\system32\inetsrv\fcgiext.ini

[Types]
*:1=RUBY
fcgi:1=RUBY

[RUBY]
ExePath=C:\ruby\bin\ruby.exe
Arguments=C:\path\to\rails_app\public\dispatch.fcgi
IgnoreDirectories=0
IgnoreExistingFiles=1
QueueLength=1000
MaxInstances=4
InstanceMaxRequests=200


6. Open up IIS, right click on "Default Web Site" and select
"Properties".

Select the "Home Directory" tab and change the "Local Path" to point
to your rails app's public directory:
C:\path\to\rails_app\public

Change the "Execute Permissions" option to "Scripts and Executables"
and apply the changes. The contents of your app's public directory
should be displayed in the IIS directory.


7. If you've got IIS 5 (definitely) or IIS 6 (I think..), go to
http://www.helicontech.com/download-isapi_rewrite.htm download the
lite version for now cause it's free and install it. I think IIS7
already has an equivalent of apache's mod_rewrite module or it allows
you to import the same conditions etc. so if you have IIS7 then don't
worry about this step


8. Remove the read only permission from this file first and then open:
C:\Program Files\Helicon\ISAPI_Rewrite\httpd.ini and add the
following:

RewriteRule ^$ index.html [QSA]
RewriteRule ^([^.]+)$ $1.html [QSA]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule  ([^.]+)$  /dispatch.fcgi?opnq=$1

save the file and re-apply the read-only permission to this file
The above is going to change your incoming requests into something IIS
will like.

9. Open IIS again, select "Properties" again, this time select the
"ISAPI Filters" tab. You should see 'isapi' listed. If you don't see
it, click add, name a filter 'isapi' and point the executable path to
C:\Program Files\Helicon\ISAPI_Rewrite\ISAPI_Rewrite.dll

Click Apply.


10. In IIS, Select the "Home Directory" tab again, click
"Configuration"... You need to add a mapping for files that have the
extension .fcgi and tell IIS to execute these files with the
fcgiext.dll that you installed in step 4. Click add.. then:

executable path = C:\WINDOWS\system32\inetsrv\fcgiext.dll
extension = .fcgi
Verbs = ALL


11. Open a command prompt and run: iisreset
This will reset IIS and reinitialise everything with all of the
changes above.

Open IIS again, refresh and click on the play icon to start IIS.


12. Open a browser and go to http://localhost
It'll take around 30 seconds to kick off the first time, but if
everything worked you should get some sort of rails error saying
there's a problem routing your request into dispatch.fcgi or something
like that. If you get some other type of error then double check
everything above again until you can get a rails error.


13. Your routes won't work properly because of the way the requests
are now coming in from IIS. The following are examples of environment
variable values when these requests come in:

Incoming from IIS to Rails App
  Path Info    : /dispatch.fcgi
  Script Name  : /dispatch.fcgi
  Query String : opnq=/controller/action?var1=foo&var2=bar
  Request_URI  : /dispatch.fcgi?opnq=/controller/action?
var1=foo&var2=bar
  Base URL     :

You need to patch ActionController's request method so that you can
transform the request into the following:
  Path Info    : /controller/action
  Script Name  : /dispatch.fcgi
  Query String : var1=foo&var2=bar
  Request_URI  : /controller/action?var1=foo&var2=bar
  Base URL     :

Go into your rails app and create a new file in your lib directory.
The following will patch ActionController's request method, catch the
incoming request and split the incoming vomit into something Rails can
understand.

#{RAILS_ROOT}/lib/action_controller_request_ext.rb

module ActionController
  class Request
    def request_uri
      orig_uri = @env['REQUEST_URI']
      new_uri = orig_uri.to_s.gsub(/^.*opnq=/, '').to_s.gsub(/\/
dispatch.fcgi/, '')
      @env['REQUEST_URI'] = new_uri
      @env['QUERY_STRING'] = ((new_uri.gsub(/^.*\?/, '') == "/") || (!
new_uri.match(/\?/))) ? "" : new_uri.gsub(/^.*\?/, '')
      @env['PATH_INFO'] = new_uri.gsub(/\?.*$/, '')
      new_uri
    end
  end
end

You can either require this file within your environment.rb or require
it in your dispatch.fcgi if you want

#{RAILS_ROOT}/public/dispatch.fcgi

require File.dirname(__FILE__) + "/../config/environment"
require 'fcgi_handler'
require File.join(RAILS_ROOT, 'lib', 'action_controller_request_ext')

RailsFCGIHandler.process!


14. Open command prompt again and reset IIS again using: iisreset

Check out your browser again http://localhost and you should see your
rails app running.. might take about 30 seconds to kick off the first
time.

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
or Rails Oceania" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/rails-oceania?hl=en.

Reply via email to