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
http://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
http://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 using RoRIIS7
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 http://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\RoRIIS7
rails -D MyApp
cd MyApp
ruby 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 http://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 http://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

http://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 http://roriis7:8080/test/about

and you should see

image

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

Comments (29)

  1. Steve Hare says:

    Hi,

    I was wondering if there’s any reason why this would not work on Server 2008?  I followed all the steps to a T, but can’t get past the 500.0 error message.  I’ve double and triple checked all the permissions, but no change.  Any help, or troubleshooting steps you may be able to provide would help.

    thanks,

    -Steve H.

  2. Daffy says:

    If you’re wanting an setup on Windows for development, check out BitNami stacks – they’ve got a Ruby one – http://bitnami.org/stack/rubystack – and a JRuby one – http://bitnami.org/stack/jrubystack

    I’ve not had any issues with it yet. But I’m not sure if it’s suitable for production environments or not.

    Daf

     >>> Thanks Daf. I do have the dev environment. I am looking for
    deployment via IIS

  3. Steve H. says:

    I had to add the IIS_USRS group to the RoRIIS7 dir and give full control to get the 500 error to go away.

  4. Ruprict says:

    I also had to uncomment out this line in the environment.rb:

    <pre>config.gem "sqlite3-ruby", :lib => "sqlite3"</pre>

  5. Frank says:

    Hi,

    I’m using server 2008, and have also followed the instructions to the letter.

    I am also stuck on the http 500 error.

    I have set the netowrk permissions, and also (as a test) allowed the "everyone" group full access to c:ruby and c:inetpubroriis7.  (this was just a test to see if it was permissions related – no joy).

    Do you have any hints as to how I can debug this?

    Ta’

    Frank

  6. nightcrawler says:

    I am also stuck on the http 500 error using Server 2008 x64, has anybody solved this ?

  7. CG says:

    I am installing redMine (RoR based ticketing system) with this guide and it works great.

    however, there is still a small problem with this configuration. In redmine , if there is a new row of data created (regardless is new issue , new follow-up , new tracker or etc) .

    After record create, redMine will redirect to show the record. It will show the 500 error  at first. If I refresh it , it will load the page correctly.  It seems like IIS could not find the new record  when it is created , but later it will work. I suspect is the caching problem of dispatch.fcgi or URL Rewrite  or Module Handler setting .

    Anybody encounter this problem , any solution ?

    IIS7 + RoR 2.2.2 (RedMine) + URL Rewrite 1.1

  8. confused says:

    Hi

    I’m using server 2008 and your simple example is running fine. The problem comes when expanding the site to handle images and css. None of the files will be forwarded. Rails log errors like "ActionController::RoutingError (No route matches "/stylesheets/main.css" with {:method=>:get}):

     public/dispatch.fcgi:24"

    You build your post on Ruslan’s post about URL rewriter.

    but it’s not used in your example?

    Is Ruslan’s proposed solution for displaying static files the way to go to get it working?

  9. confused says:

    To get it working with regular rails view helpers like <%= stylesheet_link_tag ‘main’ %>, <%= javascript_include_tag :defaults %>

    and normal tags like <img src="images/pict.gif">

    that all works well running the application on webrick.

    I added the URL revrite feature to my IIS7 site, imported the rules from Ruslan’s solution, and changed the C:windowssystem32inetsrvconfig and open

    applicationhost.config handler section path"*" to path="dispatch.fcgi"

    Finally I added virtual directories to my site having alias images,stylesheets and javascripts.

  10. Greg says:

    I’ve followed all the instructions and am on Windows 2008. Has anyone solved this error:

    HTTP Error 500.0 – Internal Server Error

    c:rubybinruby.exe – The FastCGI process exited unexpectedly

  11. Haluk Tufekci says:

    Be sure you give the following permissions:

    <Ruby> NETWORK SERVICE(Read and Execute)

    <Ruby App> NETWORK SERVICE(Read and Execute)

    <Ruby App/log> NETWORK SERVICE(Full Control)

    <Ruby App/temp> NETWORK SERVICE(Full Control)

    One last note: Account is "NETWORK SERVICE", not "NETWORK"

  12. Alexey Zakharov says:

    I have the same problem with c:rubybinruby.exe – The FastCGI process exited unexpectedly

    I set permission both to ruby and my ruby site folders. =(((

  13. Jason says:

    Me Too. Premissions set and still getting error. I even tried using the latest FastCGI Update as well and it didn’t work either.

  14. Jeff says:

    Yep same problem here Win Server 2008 x64, permissions all triple checked, and still get the blasted 500 error.  Anyone out there solved this on x64?

  15. Jeff says:

    Wow…should have paid closer attention to the rest of the comments….

    September 06, 2009 11:35 AM by Steve H.  posted the correct answer to the 500 error.  Adding permissions for IIS_IUSR group to appfolder and ruby folder cleared this error right up…good job Steve!

  16. Jeff says:

    Ok, so I can get the app running on Win64 – 2008, but if I navigate to app/login and enter Uname and PWD, I get another Internal 500 error and the app log says this:

    Log Name:      Application

    Source:        Application Error

    Date:          4/12/2010 11:20:52 AM

    Event ID:      1000

    Task Category: (100)

    Level:         Error

    Keywords:      Classic

    User:          N/A

    Computer:      WMSTUTGIS02.WILLIAMS.com

    Description:

    Faulting application name: ruby.exe, version: 1.8.6.0, time stamp: 0x48a0d73f

    Faulting module name: msvcrt-ruby18.dll, version: 1.8.6.0, time stamp: 0x48a0d73e

    Exception code: 0x40000015

    Fault offset: 0x000267f4

    Faulting process id: 0xf80

    Faulting application start time: 0x01cada5c14ce5fac

    Faulting application path: c:Rubybinruby.exe

    Faulting module path: c:Rubybinmsvcrt-ruby18.dll

    Report Id: 5cb4e26f-464f-11df-a76b-001a64635a3a

    Event Xml:

    <Event xmlns="http://schemas.microsoft.com/win/2004/08/events/event"&gt;

     <System>

       <Provider Name="Application Error" />

       <EventID Qualifiers="0">1000</EventID>

       <Level>2</Level>

       <Task>100</Task>

       <Keywords>0x80000000000000</Keywords>

       <TimeCreated SystemTime="2010-04-12T16:20:52.000000000Z" />

       <EventRecordID>959</EventRecordID>

       <Channel>Application</Channel>

       <Computer>WMSTUTGIS02.WILLIAMS.com</Computer>

       <Security />

     </System>

     <EventData>

       <Data>ruby.exe</Data>

       <Data>1.8.6.0</Data>

       <Data>48a0d73f</Data>

       <Data>msvcrt-ruby18.dll</Data>

       <Data>1.8.6.0</Data>

       <Data>48a0d73e</Data>

       <Data>40000015</Data>

       <Data>000267f4</Data>

       <Data>f80</Data>

       <Data>01cada5c14ce5fac</Data>

       <Data>c:Rubybinruby.exe</Data>

       <Data>c:Rubybinmsvcrt-ruby18.dll</Data>

       <Data>5cb4e26f-464f-11df-a76b-001a64635a3a</Data>

     </EventData>

    </Event>

    Any ideas?

  17. Konstantin says:

    I'm stack on step 14. Installing SQLite doesn't help, the window with the "We're sorry.." still remain. But fixing permission for IIS_USRS group help!

  18. vasilis says:

    blog.anlek.com/…/installing-updating-sqlite3-on-windows

    link dows not work and i am stuck on step 14 … so either I havent installed sqlite properly or something else but I am still getting the "we're sorry…" message

  19. Alex says:

    Hi,

    I am able to get a basic test-app running on Windows 7 with IIS 7 and Ruby 2.3.x.

    However, I keep getting a 500.0 error as soon as I try to set up my actual application. This app has many plugins and gems and I am beginning to think that this may be the problem.

    I have checked permissions a 100 times and I currently allow full control to both NETWORK SERVICE as well as IIS_IUSRS.

    I am at the end of my rope.  

  20. Lysa says:

    Great thanks to you for this tutorial

  21. Mark says:

    Server Error in Application "RUBY"

    Internet Information Services 7.5

    Error Summary

    HTTP Error 500.0 – Internal Server Error

    <handler> scriptProcessor could not be found in <fastCGI> application configuration

    Detailed Error Information

    Module FastCgiModule

    Notification ExecuteRequestHandler

    Handler RubyFastCGI

    Error Code 0x80070585

    Requested URL http://ruby:81/

    Physical Path C:inetpubRuby

    Logon Method Anonymous

    Logon User Anonymous

    Most likely causes:

       IIS received the request; however, an internal error occurred during the processing of the request. The root cause of this error depends on which module handles the request and what was happening in the worker process when this error occurred.

       IIS was not able to access the web.config file for the Web site or application. This can occur if the NTFS permissions are set incorrectly.

       IIS was not able to process configuration for the Web site or application.

       The authenticated user does not have permission to use this DLL.

       The request is mapped to a managed handler but the .NET Extensibility Feature is not installed.

    Things you can try:

       Ensure that the NTFS permissions for the web.config file are correct and allow access to the Web server's machine account.

       Check the event logs to see if any additional information was logged.

       Verify the permissions for the DLL.

       Install the .NET Extensibility feature if the request is mapped to a managed handler.

       Create a tracing rule to track failed requests for this HTTP status code. For more information about creating a tracing rule for failed requests, click here.

    Links and More Information This error means that there was a problem while processing the request. The request was received by the Web server, but during processing a fatal error occurred, causing the 500 error.

    View more information »

    Microsoft Knowledge Base Articles:

       294807

  22. Mark says:

    Ok, here is the thing. If I remove a parameter to Ruby interpreter, so instead of this:

    handlers>

               <add name="RubyFastCGI" path="*" verb="*" modules="FastCgiModule" scriptProcessor="d:ruby192binruby.exe|C:inetpubRubymyApppublic

    dispatch.fcgi" resourceType="Unspecified"

    requireAccess="Script" />

           </handlers>

    I would have:

    handlers>

               <add name="RubyFastCGI" path="*" verb="*" modules="FastCgiModule" scriptProcessor="d:ruby192binruby.exe" resourceType="Unspecified"

    requireAccess="Script" />

           </handlers>

    then I am getting this:

    Server Error in Application "RUBY"

    Internet Information Services 7.5

    Error Summary

    HTTP Error 500.0 – Internal Server Error

    d:Ruby192binruby.exe – The FastCGI process exited unexpectedly

    Detailed Error Information

    Module FastCgiModule

    Notification ExecuteRequestHandler

    Handler RubyFastCGI

    Error Code 0x00000001

    Requested URL http://ruby:81/

    Physical Path C:inetpubRuby

    Logon Method Anonymous

    Logon User Anonymous

    Most likely causes:

       IIS received the request; however, an internal error occurred during the processing of the request. The root cause of this error depends on which module handles the request and what was happening in the worker process when this error occurred.

       IIS was not able to access the web.config file for the Web site or application. This can occur if the NTFS permissions are set incorrectly.

       IIS was not able to process configuration for the Web site or application.

       The authenticated user does not have permission to use this DLL.

       The request is mapped to a managed handler but the .NET Extensibility Feature is not installed.

    Things you can try:

       Ensure that the NTFS permissions for the web.config file are correct and allow access to the Web server's machine account.

       Check the event logs to see if any additional information was logged.

       Verify the permissions for the DLL.

       Install the .NET Extensibility feature if the request is mapped to a managed handler.

       Create a tracing rule to track failed requests for this HTTP status code. For more information about creating a tracing rule for failed requests, click here.

    Links and More Information This error means that there was a problem while processing the request. The request was received by the Web server, but during processing a fatal error occurred, causing the 500 error.

    View more information »

    Microsoft Knowledge Base Articles:

       294807

    I have checked the permissions 1000000000000000000000000000 times.

    But the real question is whether I need to use the parameter. Do I?

  23. Hi,

    I recommend to take a look at http://www.helicontech.com/zoo which has Ruby on Rails support on IIS7 and IIS Express.

  24. Yaroslav says:

    Please try Helicon Zoo to easily configure Ruby on Rails for IIS 7 – http://www.helicontech.com/zoo

  25. anonymous says:

    just so others are aware. in Step 12: Hook up IIS to Ruby you can find the "Add Module Mapping" link from the Actions section of the "Handler Mappings" icon on the home screen.

  26. Jalpesh P Vadgama says:

    Hello All,

    I had installed Ruby on Rails with http://www.helicontech.com/zoo still its not working

    Best Regards,

    Jalpesh

  27. Pablo says:

    Hello.

    I have this error.

    HTTP Error 500.0 – Internal Server Error C:Ruby187binruby.exe – The FastCGI process exited unexpectedly

    Thanks.

  28. Dmitry Pavlov says:

    There is a way to run RoR on IIS 8 via HttpPlatformHandler – described by Scott Hanselman in his post "Announcing: Running Ruby on Rails on IIS8 (or anything else, really) with the new HttpPlatformHandler" http://www.hanselman.com/…/AnnouncingRunningRubyOnRailsOnIIS8OrAnythingElseReallyWithTheNewHttpPlatformHandler.aspx

  29. Chris Mendla says:

    If I didn't install rails with the -d and have an existing app, is there a way to install the dispatchers after the fact?

    thanks

    chris