dklangst is proud to present you this little tip:

10 Steps to Running Nitro in Apache CGI on Windows XP

I am relatively new to Nitro but have been lurking for a few months assessing if/when I wanted to jump in and give it a try. I have a new project that seems to be appropriate, so as a start I simply wanted to get it working on my laptop (3ghz P4 w/ WinXP.... yes I know, but WinXP is what I have to use for several reasons). I have noticed that Windows seems to be the stepchild for Nitro OSes (most of the main developers seem to use -nix or OsX).

So my first goal was to get the template app created by 'gen app' working.

I have Apache 1.3.33 and Mysql 4.1.19 (although the 'gen app' template does not require a DB, that is what I will be using as I progress). So here are the 10 steps I discovered to get the Nitro 'gen app' working under CGI.

  1. Install Apache if needed and ensure it is working properly... also ensure mod_rewrite and VirtualHosting are installed and working (*exercise left up to student*)
  2. Install Ruby if needed (*equally left up to student*)
  3. Install Nitro and dependancies (*ditto*)
  4. Change your directory to where you want to create your nitro application <nitro-app-path>
  5. Run
    gen app nitrotest
    (*where 'nitrotest' is the name of the Nitro app directory*)
  6. You must set the DocRoot of your site to the Nitro application 'public' directory... I chose to do it this way:
    • add a line to your hosts file in windows (*in XP at /windows/system32/drivers/etc/hosts*)
      127.0.0.1         nitrotest.local
    • add a virtual host configuration to the end of your apache config file (*you will have to find this... typically it is wherever apache is installed and in the 'conf' directory there and named 'httpd.conf'*). What you add should be something like (*changing <nitro-app-path> to the appropriate directory*):
      <VirtualHost *>
          ServerName nitrotest.local
          DocumentRoot <nitro-app-path>/nitrotest/public
          <Directory <nitro-app-path>/nitrotest/public>
              AllowOverride All
              Options +FollowSymLinks +ExecCGI
              Order allow,deny
              allow from all
          </Directory>
      </VirtualHost>
      
    • restart your apache server to reload the changed config file
  7. Create a .htaccess file in the nitrotest/public directory and paste the following into that file:
    # Redirect all requests not available on the filesystem 
    # to Nitro. By default the cgi dispatcher is used which 
    # is very slow. 
    AddHandler cgi-script .rb
    Options +FollowSymLinks +ExecCGI
    
    RewriteEngine On
    
    # Set Rewrite conditions to let Apache deliver content in the
    # js and media directories instead of sending to Nitro
    RewriteCond %{REQUEST_URI} ^/js/.*
    RewriteRule .* - [L]
    RewriteCond %{REQUEST_URI} ^/media/.*
    RewriteRule .* - [L]
    
    # Send .html files in the DocRoot via Apache if they exist
    RewriteRule ^([^.]+)$ $1.html [QSA]
    RewriteCond %{REQUEST_FILENAME} !-f
    
    # Route all other requests to Nitro thru cgi.rb
    RewriteRule ^(.*)$ cgi.rb [QSA,L]
    
    # In case Nitro experiences terminal errors.
    ErrorDocument 500 "<h2>Application error</h2>Nitro failed to start properly"
    
  8. Modify the nitrotest/public/cgi.rb file by changing the 'shebang' line (*first line in the file*) to the location of your ruby executable. Typically it should look like (*and don't forget the '-rubygems' assuming you installed nitro via gem*)
    #!c:/ruby/bin/ruby -rubygems
  9. Open your browser and type *http://nitrotest.local* into your address bar and voila, you have a simple working Nitro app on Windows (XP)

So I lied and did it in only 9 steps ;>)

It may not be fast since it is CGI and every Nitro request has to load and compile a complete Nitro run, but it gets you there as a first step.

My next goal is to see if I can get either SCGI or FastCGI to work. Will post a howto for that if I get it working.

Dave