Ruby on Rails
HowtoInstallOnWindows (Version #37)

(duplicated to RailsOnWindows)
I’ve finally made it work for me on a laptop, so I thought I’d share. These instructions are probably pretty generic across different Window PC’s. If this works for any other Windows versions, Processor types, etc., please list them here:

* Windows XP SP2 * Windows XP SP1 * Windows 2000

(I had trouble after using the one click installer in Windows 98 and 95. The first problem is that Windows 9x does not understand .cmd files Renaming .cmd files to .bat got things like gem to work. Secondly some .cmd files contain %* which again is not supported on 9x. In such circumstances %* needed to be replaced by “%1 %2 %3 %4 %5 %6 %7 %8 %9��?. I then hit couldn’t find HOME environment which required me to add

set HOME="C:\WINDOWS\DESKTOP\"

to C:\AUTOEXEC.bat. Finally, after a day’s persistent debugging I have found that the default database_manager of CGI::Session::PStore in cgi_process.rb is seemingly buggy on 9x and will cause a hang when an attempt is made to create a session in a dynamic request. Changing it to CGI::Session::MemoryStore worked around the problem and finally allowed a simple rails with WEBrick app to work. Perhaps all this should go on its own page…).

I could not get gems to work on Windows NT. It gives:

ERROR: While executing gem … Errno::ENOTCONN)

Unknown Error

when trying to update or install a gem.

Requirements

Internet connectivity

This is a remote installation to get the latest versions ruby Gems and its dependencies so an internet connection is a must.

Note: Some Windows XP users have complained about connectivity problems on initial installations, i.e. TCPServer errors and gem install—remote failures. Most often, the problems are caused by extra spyware and/or corrupted firewall settings and may require you to restore your winsock2. Before you change anything, you should try c:\netstat -ano; this will indicate port/service conflicts. See this link for more help.

Apache Webserver

This instructional is based on the use of windows as a development environment for Apache2 and Ruby on Rails. So it is assumed the webserver of choice is Apache2 of one version or another. You may install Apache2 on windows or you may use any of the following Apache2 install packages.

Apache2Triad
Wamp5
Uniform Web server
Xammp for windows

Database server

In most cases the above webserver packages include one or several opensource database servers. It is just a matter of choosing one that applies to you situation. In cases where the database server is not a typical one, refer to that softwares documentation for instructions on installation to windows.

Ruby progamming environment

Ruby one-click installer – A self-contained installer that includes the Ruby language, dozens of popular extensions, a syntax-highlighting editor and the book “Programming Ruby: The Pragmatic Programmer’s Guide��?. Platforms: Windows NT/2000/XP, (OS X in development).

Optional server software

FastCGI? and other software may be necessary in order to emulate a production server as closely as possible.

Installing the Apache2 Webserver

Install the Apache2 webserver according to the instructions in your choice of webserver package. In most cases this is just a single click on the installer icon and setting the paths to where you want things.

Using FastCGI?

The use of Fast CGI to deliver Rails applications can increase speed through in-memory caching. Place the fast CGI dll in a folder used for Apache modules in your webserver installation (check the software docs) and configure http://httpd.conf by adding this line to the module section:

 LoadModule fastcgi_module [path to the dll file]mod_fastcgi-2.4.2-AP20.dll 

Here’s an example of what you should see in your http://httpd.conf file.
LoadModule php5_module "i:/wamp/php/php5apache.dll" 
LoadModule fastcgi_module "i:/wamp/fastcgi/mod_fastcgi-2.4.2-AP20.dll" 

If you were looking just to get fastCGI support for your present installation the you can stop here. This section of instruction is purely informative as we will use another easier method for installing fastCGI by using Ruby For APache.

Additional notes on Fast CGI

I did not use RubyForApache in my initial installation and was unable to get Fast CGI working. A query on #rubyonrails led me to this article – Taming FastCGI+Apache2 on Windows which helped me fix my problems. It enabled me to fix some path related issues as the libraries in the XAMPP installation are not on the normal paths. Thanks dema-on and emlyn on IRC.
Using mod_ruby

This is not recommended when using Rails. Rails is independant and does not need mod_ruby to run.Mod_ruby is an alternative way of using Ruby to create web applications. You can use mod_ruby as CGI and have web pages containing Ruby code interpreted natively by Apache2. Mod_ruby does not have the set MVC that Rails uses and many other tools that make quick work of creating a web application. It might be best if you decide to use mod_ruby to stop at this point and not install rubyonrails. This is because we are trying to get a development server going that is similar to a web hosting enviroment and not many web hosts are going to use both mod_ruby and rubyonrails.

note: A *.dll for windows use of mod_ruby to this date does not exist. Mod_ruby installation on windows IIS would include compiling under windows using cygwin and other tools.

Install Fast CGI from Ruby For Apache

RubyForApache is an installer package for fastCGI and mod_ruby which takes the place of doing a manual installation of each module. This package use Linux shared object files and is compatible with Apache2 only. Despite the name which does not take into account Apache 1.3+ is still the defacto webserver on Linux web hosting. Again take warning that if you install mod_ruby you should not use Ruby On Rails. The reason that this package is used here because it provides the easiest method for choosing installation items from a list fastCGI,mod_ruby or mysql. Choose only fastCGI at this point do not install mod_ruby or the mysql module.

Setting up Ruby, Ruby Gems and Rails

Install Ruby

Run the Ruby one-click installer and follow the instructions accordingly.

Update the Gem package

open CMD (Start > Run > type in: cmd) then find your installation of ruby

C:\rubyinstalldirectory\bin> gem update

C:\rubyinstalldirectory\bin> gem install rails --include-dependencies

These commands may take a long time, just be patient.

Creating and Configuring a Ruby On Rails Application

Create a new Application

Open a command prompt window and use the following

C:webserverrubybin> rails C:/apache2triad/htdocs/appname

Configure mod_rewrite in .htaccess

Go to the public folder in your Rails application and open .htaccess and look for the rewrite rule:

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

and change it to:
RewriteRule ^(.*)$ dispatch.fcgi [QSA,L]

Comment out the Apache section in your .htaccess as you will reference these in your Apache httpd.conf file later.
# General Apache options

  1. AddHandler fastcgi-script .fcgi
  2. AddHandler cgi-script .cgi
  3. Options +FollowSymLinks +ExecCGI

Configure fastCGI in dispatch.fcgi

To accomodate Windows open dispatch.fcgi and change the first line to match that of your Ruby installation directory.

#!d:/ruby/bin/ruby

Configuring the Apache2 webserver

Find Apache2 conf file. In most cases the webserver package has set a link in the program listings of windows or a shortcut on your destop. But you can also find the file by surfing the file system for a path like this example:

C:/apache2triad/conf/httpd.conf. 

mod_rewrite

You must make sure that the mod_rewrite module is uncommented by removing the pound (#) in httpd.conf so that it is loaded for use by Ruby On Rails.

LoadModule rewrite_module modules/mod_rewrite.so

Virtual host

All the way at the end of file (so it is easy to find later on)
place this follow code:

#################################

  1. RUBY SETUP
    #################################

<VirtualHost *:80>
ServerName rails

DocumentRoot “c:/path/to/your/rails/app/public” <Directory “c:/path/to/your/rails/app/public/”> Options ExecCGI FollowSymLinks AllowOverride all Allow from all Order allow,deny AddHandler cgi-script .cgi AddHandler fastcgi-script .fcgi

#################################

  1. RUBY SETUP
    #################################

Have fun and good luck!!

Developing or deploying?

If you are developing on windows but will be deploying elsewhere, the recommended webserver to use for development is Webrick.

Does anyone have any WindowsSuccessStories for deploying rails in a Windows environment? — TobinHarris

Recommended tools:

* Ruby for Windows I recommend the latest stable version. People in irc report that 1.8.2 pre versions seem to work, though. * Ruby gems You will need gems to install rails. The latest stable version(s) of Ruby for Windows include rubygems. * XAMPP for Windows The almost positively easiest way to get mysql/Apache2 up and running on Windows. It also comes with mercury mail server, php4 and php5 as well as phpmyadmin preinstalled. * WAMP Even easier to install than XAMPP. Installs Apache, My SQL, and php My Admin. * Ruby For Apache installer of mod_fastcgi and mod_ruby. * Scite A very good win32 text editor (comes with the Ruby for Windows installer) More on Scite.

Questions:

* How to get a gem works behind a passworded proxy? See GemRails, Running gem install when you are behind a proxy category:Howto

(duplicated to RailsOnWindows)
I’ve finally made it work for me on a laptop, so I thought I’d share. These instructions are probably pretty generic across different Window PC’s. If this works for any other Windows versions, Processor types, etc., please list them here:

* Windows XP SP2 * Windows XP SP1 * Windows 2000

(I had trouble after using the one click installer in Windows 98 and 95. The first problem is that Windows 9x does not understand .cmd files Renaming .cmd files to .bat got things like gem to work. Secondly some .cmd files contain %* which again is not supported on 9x. In such circumstances %* needed to be replaced by “%1 %2 %3 %4 %5 %6 %7 %8 %9��?. I then hit couldn’t find HOME environment which required me to add

set HOME="C:\WINDOWS\DESKTOP\"

to C:\AUTOEXEC.bat. Finally, after a day’s persistent debugging I have found that the default database_manager of CGI::Session::PStore in cgi_process.rb is seemingly buggy on 9x and will cause a hang when an attempt is made to create a session in a dynamic request. Changing it to CGI::Session::MemoryStore worked around the problem and finally allowed a simple rails with WEBrick app to work. Perhaps all this should go on its own page…).

I could not get gems to work on Windows NT. It gives:

ERROR: While executing gem … Errno::ENOTCONN)

Unknown Error

when trying to update or install a gem.

Requirements

Internet connectivity

This is a remote installation to get the latest versions ruby Gems and its dependencies so an internet connection is a must.

Note: Some Windows XP users have complained about connectivity problems on initial installations, i.e. TCPServer errors and gem install—remote failures. Most often, the problems are caused by extra spyware and/or corrupted firewall settings and may require you to restore your winsock2. Before you change anything, you should try c:\netstat -ano; this will indicate port/service conflicts. See this link for more help.

Apache Webserver

This instructional is based on the use of windows as a development environment for Apache2 and Ruby on Rails. So it is assumed the webserver of choice is Apache2 of one version or another. You may install Apache2 on windows or you may use any of the following Apache2 install packages.

Apache2Triad
Wamp5
Uniform Web server
Xammp for windows

Database server

In most cases the above webserver packages include one or several opensource database servers. It is just a matter of choosing one that applies to you situation. In cases where the database server is not a typical one, refer to that softwares documentation for instructions on installation to windows.

Ruby progamming environment

Ruby one-click installer – A self-contained installer that includes the Ruby language, dozens of popular extensions, a syntax-highlighting editor and the book “Programming Ruby: The Pragmatic Programmer’s Guide��?. Platforms: Windows NT/2000/XP, (OS X in development).

Optional server software

FastCGI? and other software may be necessary in order to emulate a production server as closely as possible.

Installing the Apache2 Webserver

Install the Apache2 webserver according to the instructions in your choice of webserver package. In most cases this is just a single click on the installer icon and setting the paths to where you want things.

Using FastCGI?

The use of Fast CGI to deliver Rails applications can increase speed through in-memory caching. Place the fast CGI dll in a folder used for Apache modules in your webserver installation (check the software docs) and configure http://httpd.conf by adding this line to the module section:

 LoadModule fastcgi_module [path to the dll file]mod_fastcgi-2.4.2-AP20.dll 

Here’s an example of what you should see in your http://httpd.conf file.
LoadModule php5_module "i:/wamp/php/php5apache.dll" 
LoadModule fastcgi_module "i:/wamp/fastcgi/mod_fastcgi-2.4.2-AP20.dll" 

If you were looking just to get fastCGI support for your present installation the you can stop here. This section of instruction is purely informative as we will use another easier method for installing fastCGI by using Ruby For APache.

Additional notes on Fast CGI

I did not use RubyForApache in my initial installation and was unable to get Fast CGI working. A query on #rubyonrails led me to this article – Taming FastCGI+Apache2 on Windows which helped me fix my problems. It enabled me to fix some path related issues as the libraries in the XAMPP installation are not on the normal paths. Thanks dema-on and emlyn on IRC.
Using mod_ruby

This is not recommended when using Rails. Rails is independant and does not need mod_ruby to run.Mod_ruby is an alternative way of using Ruby to create web applications. You can use mod_ruby as CGI and have web pages containing Ruby code interpreted natively by Apache2. Mod_ruby does not have the set MVC that Rails uses and many other tools that make quick work of creating a web application. It might be best if you decide to use mod_ruby to stop at this point and not install rubyonrails. This is because we are trying to get a development server going that is similar to a web hosting enviroment and not many web hosts are going to use both mod_ruby and rubyonrails.

note: A *.dll for windows use of mod_ruby to this date does not exist. Mod_ruby installation on windows IIS would include compiling under windows using cygwin and other tools.

Install Fast CGI from Ruby For Apache

RubyForApache is an installer package for fastCGI and mod_ruby which takes the place of doing a manual installation of each module. This package use Linux shared object files and is compatible with Apache2 only. Despite the name which does not take into account Apache 1.3+ is still the defacto webserver on Linux web hosting. Again take warning that if you install mod_ruby you should not use Ruby On Rails. The reason that this package is used here because it provides the easiest method for choosing installation items from a list fastCGI,mod_ruby or mysql. Choose only fastCGI at this point do not install mod_ruby or the mysql module.

Setting up Ruby, Ruby Gems and Rails

Install Ruby

Run the Ruby one-click installer and follow the instructions accordingly.

Update the Gem package

open CMD (Start > Run > type in: cmd) then find your installation of ruby

C:\rubyinstalldirectory\bin> gem update

C:\rubyinstalldirectory\bin> gem install rails --include-dependencies

These commands may take a long time, just be patient.

Creating and Configuring a Ruby On Rails Application

Create a new Application

Open a command prompt window and use the following

C:webserverrubybin> rails C:/apache2triad/htdocs/appname

Configure mod_rewrite in .htaccess

Go to the public folder in your Rails application and open .htaccess and look for the rewrite rule:

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

and change it to:
RewriteRule ^(.*)$ dispatch.fcgi [QSA,L]

Comment out the Apache section in your .htaccess as you will reference these in your Apache httpd.conf file later.
# General Apache options

  1. AddHandler fastcgi-script .fcgi
  2. AddHandler cgi-script .cgi
  3. Options +FollowSymLinks +ExecCGI

Configure fastCGI in dispatch.fcgi

To accomodate Windows open dispatch.fcgi and change the first line to match that of your Ruby installation directory.

#!d:/ruby/bin/ruby

Configuring the Apache2 webserver

Find Apache2 conf file. In most cases the webserver package has set a link in the program listings of windows or a shortcut on your destop. But you can also find the file by surfing the file system for a path like this example:

C:/apache2triad/conf/httpd.conf. 

mod_rewrite

You must make sure that the mod_rewrite module is uncommented by removing the pound (#) in httpd.conf so that it is loaded for use by Ruby On Rails.

LoadModule rewrite_module modules/mod_rewrite.so

Virtual host

All the way at the end of file (so it is easy to find later on)
place this follow code:

#################################

  1. RUBY SETUP
    #################################

<VirtualHost *:80>
ServerName rails

DocumentRoot “c:/path/to/your/rails/app/public” <Directory “c:/path/to/your/rails/app/public/”> Options ExecCGI FollowSymLinks AllowOverride all Allow from all Order allow,deny AddHandler cgi-script .cgi AddHandler fastcgi-script .fcgi

#################################

  1. RUBY SETUP
    #################################

Have fun and good luck!!

Developing or deploying?

If you are developing on windows but will be deploying elsewhere, the recommended webserver to use for development is Webrick.

Does anyone have any WindowsSuccessStories for deploying rails in a Windows environment? — TobinHarris

Recommended tools:

* Ruby for Windows I recommend the latest stable version. People in irc report that 1.8.2 pre versions seem to work, though. * Ruby gems You will need gems to install rails. The latest stable version(s) of Ruby for Windows include rubygems. * XAMPP for Windows The almost positively easiest way to get mysql/Apache2 up and running on Windows. It also comes with mercury mail server, php4 and php5 as well as phpmyadmin preinstalled. * WAMP Even easier to install than XAMPP. Installs Apache, My SQL, and php My Admin. * Ruby For Apache installer of mod_fastcgi and mod_ruby. * Scite A very good win32 text editor (comes with the Ruby for Windows installer) More on Scite.

Questions:

* How to get a gem works behind a passworded proxy? See GemRails, Running gem install when you are behind a proxy category:Howto