Ruby on Rails
Fast CGI and Apache2 for Windows without VirtualHosts

This is an “alternate ending” to Fast CGI and Apache2 for Windows XP. All of the setup described there must be done here as well, except for the final part that sets up a VirtualHost for your Rails app.

This page shows how to setup your server so you can access your Rails app like this:

<a href="http://www.myhostname.com/myapp">www.myhostname.com/myapp</a>

This is part should be tuned depending on your needs; I just want to run a few small development apps on my box without having to setup virtual hosts.

We need to make a few changes to three files.

Changing the httpd.conf

First, let’s start with the httpd.conf file. Add the following to the end of the file.


Alias /myapp/ "C:/path/to/myapp/public/"

<Directory “C:/path/to/myapp/public”>
AddHandler fastcgi-script .fcgi
Options +ExecCGI
AllowOverride all
Allow from all
Order allow,deny
< /Directory>

FastCgiServer /path/to/myapp/public/dispatch.fcgi -processes 1

This sets up /myapp to point to your rails applications. It says that any urls ending with .fcgi will be sent to the fastcgi-script and it creates a single Ruby process (started at Apache startup) to handle those requests. See other Rails documentation for more on how to set FastCgiServer parameters properly to start more processes or to use a specific environment (like production). If your /path/to/myapp contains spaces you may have to surround it with quotes in the FastCgiServer line as well.

Changing the .htaccess file

The other file we need to change is the C:/path/to/myapp/public/.htaccess file in the Rails application itself.

Find these lines, and comment them out. We’ve already set the handler and the options.

# General Apache options
AddHandler fastcgi-script .fcgi
AddHandler cgi-script .cgi
Options +FollowSymLinks +ExecCGI

Now we have this:

# General Apache options
#AddHandler fastcgi-script .fcgi
#AddHandler cgi-script .cgi
#Options +FollowSymLinks +ExecCGI

Now find this line:

RewriteRule ^(.*)$ dispatch.cgi [QSA,L]

and change it to use the fastcgi, and ALSO, use the right Alias.

RewriteRule ^(.*)$ /myapp/dispatch.fcgi [QSA,L]

and one more, find the line:

#   RewriteBase /myrailsapp

and change it to use your app dir as base:

RewriteBase /myapp

Finally, if you use an ErrorDocument?, add the Alias to it:

# In case Rails experiences terminal errors
ErrorDocument 500 /500.html
ErrorDocument 404 /404.html

to this:

# In case Rails experiences terminal errors
ErrorDocument 500 /myapp/500.html
ErrorDocument 404 /myapp/404.html

Changing the dispatch.fcgi

This snippet is from Fast CGI and Apache2 for Windows XP.

Open dispatch.fcgi and change the first line to


#!c:/ruby/bin/ruby


to accomodate Windows

Done

Now you should be able to start Apache2 and browse to

<a href="http://www.myhostname.com/myapp">www.myhostname.com/myapp</a>

and see your nice shiny new Rails app responding.