Ruby On Rails with IIS 7 - Reloaded

In my last post I mentioned getting into Ruby and making MABUILD and rake work together.
I think I found a better way to do the same with PowerShell integration, which I will
write up sometime this week.

Now, it is inevitable that Ruby leads to Ruby On Rails. I needed to get RoR work on my dev machine with VISTA SP1 and IIS7.
I was little surprised to find that there are very few articles on this. A few I found were outdated. Then I landed on Ruslan's post.
It got me to a point but then I was stuck. So I walked to Ruslan's office and we discussed this quite a bit. I went back to my office and researched this some more.
I finally got this working after about 3 days of stumbling around. So here is the post that builds on Ruslan's
post and clarifies a few things. Mostly I wanted to make sure that even folks like me, who are beginners in the Ruby universe,
could follow the steps to get RoR and IIS 7 working.

I am starting here with a clean system with VISTA SP1.

Step 1:   INSTAL IIS AND CGI

Go to control panel, Programs and Features and then select "Turn features on or off". You can get there quicker
by typing appwiz.cpl on a command prompt and then selecting "Turn features on or off " from the left side
image

From the features select World Wide Web Services
and make sure that you select the following

  1. REQUIRED: CGI. This is the same as the FastCGI support
  2. REQUIRED: IIS Management Console
  3. OPTIONAL: Custom HTTP Features: Static Content, etc
    [We will use this to check if IIS is installed correctly]
  4. OPTIONAL : Other health and diagnostics info as
    Shows in the picture below

image

Click OK and let the Windows install IIS and FastCGI for you.

Step 2:   VERIFY THAT IIS IS WORKING

Once installed you can verify that the IIS is installed by going to the
https://localhost/iisstart.htm
image

Please note: If you did not enable STATIC CONTENT feature when you installed, you will get a 404 NOT FOUND.
You see the file right there but you still get 404 NOT FOUND. Security aside, it would be great
if there is a more easier way to diagnose this, I ended up researching this for more than 3 hours wondering
why am I getting the 404 not found. Anyway, now you know and you don't need to waste those hours.
Again, enable the static content feature to be able to see this static content page.

 

Step 3: INSTALL RUBY

Navigate to Ruby 1.8.6 One-Click Installer and install RUBY
CAUTION: DONT INSTALL TO A FOLDER that has SPACES in the name or its path. like "C:\program Files\Ruby"
I had strange errors and I had to reinstall RUBY. It is best to stick with the C:\Ruby.
As a side and tangential note, what's up with installing to C:\Ruby? Aren't the people in that
alternate universe hate installing to root directories like C:\? Why can't it default to C:\Program Files\Ruby?
RUBY is supposed to make you HAPPY!! Huh!

 

Step 4: VERIFY RUBY IS IN THE PATH

RUBY Installation should have added the C:\ruby\bin [or whatever the path you gave] to the path.
Open a command prompt; type "SET PATH" and look at the path. You should see the ruby\bin in the path.
If not, no big deal, add ruby to the path in the System Variables.
Type ruby -help to see that you get some help on the screen. This verifies that Ruby is indeed installed.

 

Step 5: INSTALL RAILS

on a command prompt, type "Gem Install Rails". [The dependencies are already
included, contrary to popular belief that suggests the -includedependencies option
is required to do so]
Once installed, do "gem list" to list the gems locally installed. You should see
something like this - which should include rails.

C:\Windows\system32>gem list

*** LOCAL GEMS ***

actionmailer (2.3.2)
actionpack (2.3.2)
activerecord (2.3.2)
activeresource (2.3.2)
activesupport (2.3.2)
fxri (0.3.6)
fxruby (1.6.16)
hpricot (0.6.164)
log4r (1.0.5)
ptools (1.1.6)
rails (2.3.2)
rake (0.8.7, 0.8.1)
ruby-opengl (0.60.0)
test-unit (2.0.1)
win32-api (1.2.1, 1.2.0)
win32-clipboard (0.4.4)
win32-dir (0.3.2)
win32-eventlog (0.5.0)
win32-file (0.5.5)
win32-file-stat (1.3.1)
win32-process (0.5.9)
win32-sapi (0.1.4)
win32-sound (0.4.1)
windows-api (0.2.4)
windows-pr (0.9.3)

Step 6: Install FASTCGI Update for IIS7
https://www.microsoft.com/downloads/details.aspx?FamilyID=19600729-8470-4956-a276-200450d814bd&displaylang=en&Hash=CUX9vrzjILBL3AghMTxtsgswXdorhJT4JhGOGHeRvFL9AQlhlkUkNtnVcQflyQD7VwtQyh51gAxTnsa4f4OlBA%3d%3d

I am not quite sure if this is a general update for FastCGI or just for PHP. To avoid hitting my head against a wall, I installed this anyway.

Step 7: Pretend that you are hosting a website called RoRIIS7

Add a HOST Entry so that the name resolver won't go out to the DNS Server.
Don't forget to use an administrative command prompt from which you
launch notepad. edit Windows\System32\Driver\Etc\Hosts like below.
image

Step 8 Add a new Website to IIS

Go to C:\InetPub [or where ever you installed the inetpub to]

create a directory called RoRIIS7. We are not touching the wwwroot directory for this experiment.
i will post an update dealing with default web site later.

Open MMC, Add the Internet Services Manager to the MMC Console.
Expand the IIS Manager. It will show the local web server.
Click on Add WebSite to add a website like below
image

Here we are adding a new WebSite RoRIIS7
mapped to the physical directory C:\Inetpub\RoRIIS7
Please note that the HostName we are usingRoRIIS7
AND that I am using port 8080
image

The website should start.

Step 9 Verify that the new website is working

To verify that the website is working, copy the IISSTART.HTM and the
welcome.png files into the RoRIIS7 directory.
Then navigate to https://RoRIIS7/iisstart.htm
You should see a page similar to step 2.

 

Step 10 Generate a RAILS APP

NOTE: When you generate the Rails app, make sure that
you use -D option. -D option generated the dispatchers
for CGI and FastCGI

Luanch CMD prompt as administrator
cd C:\inetpub\RoRIIS7rails -D MyAppcd MyAppruby script\generate Controller Test Index

 

Step 11 Generate a RAILS APP

Modify the app\controllers\test_controller.rb like below
This will enable it to display some test when we navigate to this URL

class TestController < ApplicationController
   def index
      render :text=>"The index action"
   end
   def about
      render :text=>"The about action"
   end
end

Step 12 Hook up IIS to Ruby

So far, we have IIS Setup and a Ruby App Setup
We need to hook them together now.

Go to the MMC/Internet Services Manager, Go to the site RoRIIS7 in the
MMC snapin. We are now going to add a module mapping

image

We are mapping * ==> All requests To the FastCGI Module.
The executable we use is of course the ruby interpreter.
But then there you see a PIPE character and the path to the
dispatch.fcgi. The reason is that Ruby by iteself does not handle
the FCGI. The FCGI handling is provided by the Rails
Dispatcher.

Once you add the mapping go to
C:\windows\system32\inetsrv\config and open
applicationhost.config
In this config file you should see a section for fast cgi

<fastCgi>
    <application fullPath="C:\ruby\bin\ruby.exe" arguments="C:\inetpub\RoRIIS7\MyApp\public\dispatch.fcgi" />
</fastCgi>

and another section for
the module mapping.

</system.webServer>
<location path="RoRIIS7">
    <system.webServer>
        <handlers>
            <add name="RubyFastCGI" path="*" verb="*" modules="FastCgiModule" scriptProcessor="C:\ruby\bin\ruby.exe|C:\inetpub\RoRIIS7\MyApp\public\dispatch.fcgi" resourceType="Unspecified" />
        </handlers>
    </system.webServer>

These sections are created for you when you added the module mapping
through the GUI above. Now, you could directly edit the file yourself if you wanted to.

Sensing the smell of completion you go to https://roriis7/test/about
but then you are greeted by the
image

Step 13 Fixing Permissions

When working with IIS, I always turn on the security audit.
Turning the security audit on can it self be somewhat of a challenge.
Without going into detail, what is required apparently is to
grant NETWORK Service Account permissions to the RoRIIS7 Folder.
Since Ruby will write some logfiles etc to that dir. You could
possibly fine tune this later if you needed to.
image

Do an IISRESET and go visit https://roriis7:8080/test/about
OOPS! What went wrong now?
image
Apparently the RAILS needs SQLITE and it is not happy that it can't find SQLLite

Step 14 Installing SQLITE and the SQLLITE GEM

Download SQLITE-3.6.15 ZIP file and place the exe in the Ruby\Bin directory
this is the command line config  tool

Download SQLITEDLL-3.6.15 ZIP and place the dll in the system32 directory.
This is the engine for SQLITE.

Now we need to install the GEM

https://blog.anlek.com/2008/09/installing-updating-sqlite3-on-windows/ has the
tip on getting this done

gem install --version 1.2.3 sqlite3-ruby

Step 14 COMPLETE!!!

Now you navigate to https://roriis7:8080/test/about

and you should see

image

There you go ladies and gentlemen, I give you Ruby On Rails with IIS7