Hosting Ruby on Rails Application on IIS (Windows)

Recently I have been trying to host a ruby on rails application on IIS and after some tiresome  hours ,  I found out that it is actually possible to do so.

With the introduction of httpPlatformhandler module in IIS  , the windows now have the ability to host applications of  ruby,java,node.js etc  with considerable stability . Here are the steps that I followed while hosting helpy.io,an open source help desk application running on ruby on rails is given below.

Requirements

  • IIS 8.0 or above
  • Ruby 2.2
  • Rails 4.2.6
  • Postgres SQL
  • httpPlatformHandler in IIS

** All the requirements here is not specific  to all ruby on rails application , but on our sample application  helpy.io .

Steps to follow

The first thing  is to verify  whether we have IIS 8.0 or above  installed on our system , currently only window 8 or above is said to support IIS 8.0.Install httpPlatformhandler and railsInstaller  on your system. By installing railsInstaller for ruby 2.2  we get ruby 2.2 ,rails 4.2.6 ,git ,devkit etc .

If you don’t have  the required database server installed on your system, install the same . For our sample application we require postgres sql, so Install postgres Sql  on your system. To begin, clone Helpy from the official repository to your local system Copy the folder of our source code  and paste it in C:\inetpub\wwwroot(if you are going to host inside default website)  or  inside website folder you are are going to host this application.

Open your default website (or whichever website folder we copied our application) in   iis  and right-click  our  folder in IIS Manager and “Convert to Application.”.

Open the cmd.exe (Run as administrator) and run the following commands

gem install rails

gem install puma

gem install bundle

** this is the server we are using to host our application ,you may use others servers like webbrick ,thin etc depending on your requirement

Go to our application folder and run command

bundle install

**On bundle install if there are unsupported gems , remove them from GEMLOCK file if they are related to unicorn or other servers that are linux dependent.

Configure your database.yml folder in config folder of our application .After configuring your database run the following command on cmd.

 rake db:schema:load

Configure config.ru of our application so that  it will add a relative config path of ‘/helpymaster’ to website path.

require ::File.expand_path(‘../config/environment’, __FILE__)
Rails.application.config.relative_url_root = ‘/helpymaster’ # my application folder
map Rails.application.config.relative_url_root
run Rails.application

And comes the main part, add the web.config file show below to root folder of the website (its c:\inetpub\wwwroot if its default website).

<?xml version=”1.0″ encoding=”UTF-8″?>

<configuration>

<system.webServer>

<handlers>

<add name=”httpplatformhandler” path=”*” verb=”*” modules=”httpPlatformHandler” resourceType=”Unspecified” requireAccess=”Script” />

</handlers>

<httpPlatform stdoutLogEnabled=”true” processesPerApplication=”1″ stdoutLogFile=”C:\inetpub\wwwroot\rails\helpymaster\log\rails.log” startupTimeLimit=”200″ processPath=”c:\RailsInstaller\Ruby2.2.0\bin\ruby.exe”

arguments=”&quot;C:\RailsInstaller\Ruby2.2.0\bin\puma&quot; –env test –dir c:\inetpub\wwwroot\rails\helpymaster -p %HTTP_PLATFORM_PORT%  -w0″>

</httpPlatform>

</system.webServer>

</configuration>

**make sure IIS_IUSR have permission in our folder so that we can get logs for application

and its ready !! (initial load of application may take some time)

heply.io

 

4 thoughts on “Hosting Ruby on Rails Application on IIS (Windows)

  1. Hi,

    I am trying to configure this with my app that is running in root folder (inetpub/wwwroot). When I run puma manualy and connect to local puma port on 3000, application works, but when trying to access via IIS, there is error in log file:
    *** SIGUSR2 not implemented, signal based restart unavailable!
    *** SIGUSR1 not implemented, signal based restart unavailable!
    *** SIGHUP not implemented, signal based logs reopening unavailable!
    Puma starting in single mode…
    * Version 3.6.2 (ruby 2.2.4-p230), codename: Sleepy Sunday Serenity
    * Min threads: 5, max threads: 5
    * Environment: production
    ERROR: No application configured, nothing to run

    Any idea how to configure application?

    Thanks,

    Ratko

    Liked by 1 person

  2. Hi,
    After playing with web.config, now different error in log file:
    ERROR: daemon mode not supported on Windows

    the -w0 is specified, also workers removed from puma.rb file.

    any idea?

    Liked by 1 person

  3. Finally made it work with different web.config file.
    I have one other question, what about static files? How to get it work directly from IIS? I have been using before URL 2.0 rewrite module with Helicon Zoo, but how to do it with httpPlatformhandler?

    Liked by 1 person

Leave a comment