(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:
(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\"
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 Errorwhen trying to update or install a gem.
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.
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
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 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).
FastCGI? and other software may be necessary in order to emulate a production server as closely as possible.
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.
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
LoadModule php5_module "i:/wamp/php/php5apache.dll"
LoadModule fastcgi_module "i:/wamp/fastcgi/mod_fastcgi-2.4.2-AP20.dll"
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.
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.
Run the Ruby one-click installer and follow the instructions accordingly.
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.
Open a command prompt window and use the following
C:webserverrubybin> rails C:/apache2triad/htdocs/appname
Go to the public folder in your Rails application and open .htaccess and look for the rewrite rule:
RewriteRule ^(.*)$ dispatch.cgi [QSA,L]
RewriteRule ^(.*)$ dispatch.fcgi [QSA,L]
httpd.conf file later.# General Apache options
- AddHandler fastcgi-script .fcgi
- AddHandler cgi-script .cgi
- Options +FollowSymLinks +ExecCGI
To accomodate Windows open dispatch.fcgi and change the first line to match that of your Ruby installation directory.
#!d:/ruby/bin/ruby
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.
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
All the way at the end of file (so it is easy to find later on)
place this follow code:
#################################
- 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
#################################
- RUBY SETUP
#################################
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
(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:
(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\"
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 Errorwhen trying to update or install a gem.
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.
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
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 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).
FastCGI? and other software may be necessary in order to emulate a production server as closely as possible.
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.
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
LoadModule php5_module "i:/wamp/php/php5apache.dll"
LoadModule fastcgi_module "i:/wamp/fastcgi/mod_fastcgi-2.4.2-AP20.dll"
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.
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.
Run the Ruby one-click installer and follow the instructions accordingly.
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.
Open a command prompt window and use the following
C:webserverrubybin> rails C:/apache2triad/htdocs/appname
Go to the public folder in your Rails application and open .htaccess and look for the rewrite rule:
RewriteRule ^(.*)$ dispatch.cgi [QSA,L]
RewriteRule ^(.*)$ dispatch.fcgi [QSA,L]
httpd.conf file later.# General Apache options
- AddHandler fastcgi-script .fcgi
- AddHandler cgi-script .cgi
- Options +FollowSymLinks +ExecCGI
To accomodate Windows open dispatch.fcgi and change the first line to match that of your Ruby installation directory.
#!d:/ruby/bin/ruby
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.
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
All the way at the end of file (so it is easy to find later on)
place this follow code:
#################################
- 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
#################################
- RUBY SETUP
#################################
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