Since The original tech preview release of FastCGI last year, we ' ve been seeing a lot of requests for getting Ruby on Rail s running with our FastCGI. Theoretically, since the FastCGI component uses a standard protocol to support fastcgi-enabled applications, this shouldnt Be a issue-but, in practice, this is very far from reality. After factoring in Setup problems, configuration, and variations on runtime Behavior/protocol deviations, every single F astcgi application we ' ve looked at have required quite some effort to support properly.
So, for FastCGI Tech Preview 2, I spent some time researching what it would take to enable Ruby on Rails, resulting in "ex Perimental "RoR support in the TP2 release. It is "experimental" because we do only limited testing, and given our lack of experience with Ruby It very Whether a real Ruby application would work as expected at the this point.
I am confident that the experience can is improved significantly with community testing, and any necessary fixes to both T He FastCGI component and Ruby. I am looking forward to any Feedback/bug reports so can help us get there-please feel free to leave comments on the BL OG, or post to IIS FastCGI forums.
Without further ado, these is the ten steps get RoR working with FastCGI TP2:
Read This first-platform limitations
The steps below can be used-install Ruby on Rails on a Windows Server 2003 operating system, and configure it To work with the Microsoft IIS FastCGI Technical Preview 2 release. Unfortunately Windows XP does not support the required configuration necessary for the FastCGI TP2 component to run RoR, a nd Windows Vista ' s version of FastCGI TP2 uses a different mechanism to run RoR (post "How to get" that working in the NE AR future). The initial steps to install Ruby in Rails described here is similar for Windows XP, Windows Server 2003, and Windows Vis Ta.
FastCGI TP2 Installation
1) Download and install FastCGI Technical Preview 2
Download the appropriate TP2 package for your OS, which in this case means either the IIS6 32bit FastCGI or IIS6 64bit Fas tcgi. You can read more about this on my previous blog post. Here is the synopsis of the Install steps:
This would install FastCGI on your machine, and enable us to configure it manually later. We'll not be using the automatic configuration support in the installer because we'll need some customizations specifi C for RoR later.
Ruby Installation
2) Download and install Ruby(latest tested version was 1.8.5-22 Final)
3) Install Rails Open a new command line window, and run the Gem installer:
> gem install rails--include-dependencies
4) Download and install RoR IIS extensions
The RubyForIIS.exe package contains the FastCGI client library on which RoR are dependent in order to use its dispatch.fcgi Script. During the installation, the installer would ask for the location of the Ruby directory-is sure to point the Installe R to the directory where you are installed Ruby, for example, F:ruby.
During the installation, you may get a error "Unable to write to file ... msvcp7.dll"-press Ignore to continue. If you want to double-check this everything went well, open a command prompt, and type in: > IRB <enter> > require ' fcgi ' <enter> If You see "true" and then its installed correctly. If not, re-install and give the right path of this time.
5) Fix the Ruby CGI script
This was a workaround for a iis-specific behavior in Ruby that actually does does work with iis. feel the irony.  ; Quick background-nph, or No parsed Headers, is a CGI mode of operation in which the CGI program produces a complete RESP Onse including the HTTP headers, instead of supplying the headers to the Web server and letting the webserver manage them. Most of today's webservers, including IIS, manage response headers on their Own-for example, IIS enables a number of Web server features that modify response headers in order to enable functionality like caching, compression, etc.  ; Ruby ' s CGI script assumes that IIS always requires NPH, and this of course completely breaks the FastCGI component because It does not even support NPH The funnier thing are that even IIS CGI does isn't require NPH, and doesnt use it by def ault. This is one of the things so totally makes sense to being fixed in a future Rails release to provide a more COH Esive Experience onIis.
Open <f:ruby>libruby1.8cgi.rb, and edit line 559 of the script to remove: "Or/iis/n.match (env_table ([' Server_software '])".
You can also download the already fixed script if you dont want to do surgery yourself.
Creating a sample Ruby application
At this point, if you followed the instructions above, you should has Ruby on Rails installed and ready to go on your Win Dows Machine. Now, we'll create a sample RoR application to use with the FastCGI component:
6) Create a sample Ruby app
Open a command line window, change to a base directory where you want to create your app, and type:
> rails myapp > cd myapp > Ruby scriptgenerate Controller test
This creates the MyApp RoR application, and then generates a sample "test" RoR controller. Edit This controller to display some useful stuff by opening appcontrollertest_controller.rb, and pasting the fol Lowing into it:
Class TestController < Applicationcontroller def index render:text=> "The Index Action" end def about Render:text=> "Testing App v1.0" end end
Configure the RoR application with IIS and FastCGI
We are almost there and so don ' t panic. I promise to not exceed ten steps
7) Create A website for your RoR app
Create a new website on port Bayi pointing to the public directory of your Rails app, which for me is f:rubymy Apppublic:
8) Create The RoR FastCGI handler mapping
Because RoR uses SEF (search engine friendly) URLs, it needs to use a wildcard mapping to forward all requests to FastCGI /RoR mapping-unlike PHP, which requires. PHP files to is mapped to the php/fastcgi mapping. Because of reliance on wildcard mapping, FastCGI can-only is used to run RoR on Windows Server 2003 (since Windows XP ' s VE Rsion of IIS doesnt support wildcard mappings). This was the sole reason why this walkthrough was limited to W2K3.
To create the mapping, click the ' Configuration ' button on the website, and ' Insert ' the handler mapping to ' Fcgiext.dll ' FastCGI ISAPI Handler (which you installed in step 1):
Be sure to clear the "Verify that file exists" checkbox.
9) Create The FastCGI application pool for your website
If you remember in step 1, when we installed the FastCGI TP2 package, we didnt use the installer's support for registering A FastCGI program. This was because RoR requires some custom settings in the FastCGI config file, the installer doesnt surface.
Because of this, we'll manually create this configuration by editing the %windir%system32inetsrvfcgiext.ini con figuration file (NOTE that for 64bit installations, you'll also need to make the same edits to %windir%syswow64inets Rvfcgiext.ini):
[Types] *:85358523=ruby
[Ruby] Exepath=f:rubybinruby.exe arguments=f:rubymyapppublicdispatch.fcgi ignoredirectories=0 Ignoreexistingfiles=1 queuelength=1000 maxinstances=4 instancetimeout=30 instancemaxrequests=200
-Replace the exepath with the path to your ruby.exe. -Replace the Arguments with the path the dispatch.fcgi script inside your application. -Replace the "85358523" number above with your site ID. You could omit this if is not a planning to run multiple Ruby applications on your machine. You can get it from the logging properties of your website:
This configuration shows the several new configuration/behavior features we needed to add to TP2 in order to get Ruby wo Rking. This includes-specifying arguments to the FastCGI executable (per-pool), the ability to scope FastCGI Extensio n mappings to a particular site ID (so-you can map the same extension to different pools for different sites), and th e ability to execute as a wildcard mapping, the only processes files, does not exist on disk. More information at all of these later.
Ten) you are done!
At here, you should is up and running. Hit up http://localhost:81/test/about, and you should get the RoR response from our test controller.
Please try the your real RoR apps, and let me know how it went/what issues your hit. Your feedback would be instrumental on getting to a production quality FastCGI support for RoR in a future release. Feel free to leave comments on this blog, or hits us up at the FastCGI forums on www.iis.net.
Finally, I want to thank Brian Hogan, without whose invaluable help in explaining the workings of Ruby on Rails and how to Get it installed on Windows, I wouldn ' t has been able to get even this far. He has a book on Ruby in Rails coming out soon, and I hope so we can get IIS FastCGI and RoR to play well enough togethe R to Bes mentioned in it
Ten steps to get Ruby on Rails running on Windows with IIS FastCGI