After we had our WAMP local server setup done in Part 1 and Part 2, and booting it online via No-IP dynamic DNS service, it’s time now to talk about installing Ruby on Rails on our server and use Apache 2 along with FastCGI as the webserver for the first option and Mongrel for the second, we will also install few ruby libraries that are commonly used and ensure that they are working and functioning properly by installing a ready rails script.
Ruby
Ruby is a pure object oriented programming language, created by Yukihiro Matsumoto from Japan around 11 years ago, first it was only in Japanese language, and then got translated into English around 5-6 years ago, where it had an exposure success and a great support.
For Windows the simplest way to install Ruby is via RubyInstaller, the latest stable release is version 1.8.2-15 but we should get version 1.8.4-17 RC2 (this will be explained later) as we are going to prepare for Mongrel as a webserver, you can use 1.8.2 if you will use Apache-FastCGI option only, but version 1.8.4 is more recommended for both cases.
Note: If you are running any previous version of Ruby and upgrading to Ruby 1.8.4 you may face a problem with your existing Rails applications: “Invalid char `\002′ in expression” this error happens because of some wrong tabs interpreting in windows, in order to solve it simply use your preferred editor (I use Notepad++) to replace all tabs by spaces as Ben Reubenstein advised.
So after you download the executable file from RubyForge, run it and don’t forget to change the setup directory to D:/Development/ruby (the directory we’ve created to host our development programs files in Part 1).

Ruby is now installed on our system, let’s try the lovely IRB that comes with it. IRB is an interactive command-line interpreter, which allows us to simply type our code lines and see the results on the spot.
Start the command line (Start->Run->cmd), simply enter the command “irb” to start, and to exit you can type “exit”.
D:\\development>irb irb(main):001:0> s = String.new => "" irb(main):002:0> s = "Hello World!" => "Hello World!" irb(main):003:0> n = 3 => 3 irb(main):004:0> sn = s << n.to_s => "Hello World!3" irb(main):005:0> exit
You can know more about Ruby (if you don’t already know) from Wikipedia Ruby Programming Language page, and now let’s move on to see some more Ruby goodness, let’s meet RubyGems.
RubyGems
RubyGems is the standard packaging system for Ruby, it simplify the distribution of Ruby third party libraries and projects by packing them in a standard format and then allowing us to install it in another simple way too (this is what we will do with Rails).
First download the Ruby Gems 0.8.11 zip file from RubyForge, unzip it, and then run the setup.rb file which will take care of the rest.
Installing Ruby Gems will add a new command “gem” that can be used from the command prompt to install, update and build gem packages. Now we will use it to install Rails and many other libraries by simply typing a single command line and let it take care of the rest.
Ruby on Rails
Ruby on Rails aka Rails aka RoR is the web framework of Ruby, created almost three years back by David Heinemeier Hansson as an extraction of his work on BaseCamp (a product of 37Signals), maintained now by a list of talented developers in the core team that came from different backgrounds to help Rails be the best friend of every web developer.
RoR framework implemented to demonstrate a better MVC architecture that follows the DRY concept, which to help us create better applications in less time and more solid way, personally I moved to Rails because it allowed me to spend more time on algorithms and real programming work instead of just worrying about the regular stuff that we do everyday like connecting to the database and the other
CRUD work.
We will install Rails and all its dependencies via RubyGems using “gem install” command, that will first search for the gem file locally, then attempt the remote installation from the robyforge gem repository:
D:\\development>gem install rails --include-dependencies Attempting local installation of 'rails' Local gem file not found: rails*.gem Attempting remote installation of 'rails' Updating Gem source index for: http://gems.rubyforge.org Successfully installed rails-1.1.2
If you are not able to connect to the internet from the command line then you have to install Rails locally by downloading Rails 1.1.2 and its dependencies: ActionMailer 1.2.1, ActionPack 1.12.1, ActionWebservice 1.1.2, ActiveRecord 1.14.2 and ActiveSupport 1.3.1 as stand alone gems, place them in the directory were you want to run the gem command so it will be able to find them, let’s say inside D:\Development and see:
cd d:\\development D:\\development>gem install activesupport Attempting local installation of 'activesupport' Successfully installed activesupport, version 1.3.1 Installing RDoc documentation for activesupport-1.3.1... D:\\development>gem install actionpack Attempting local installation of 'actionpack' Successfully installed actionpack, version 1.12.1 Installing RDoc documentation for actionpack-1.12.1... D:\\development>gem install actionmailer Attempting local installation of 'actionmailer' Successfully installed actionmailer, version 1.2.1 Installing RDoc documentation for actionmailer-1.2.1... D:\\development>gem install activerecord Attempting local installation of 'activerecord' Successfully installed activerecord, version 1.14.2 Installing RDoc documentation for activerecord-1.14.2... D:\\development>gem install actionwebservice Attempting local installation of 'actionwebservice' Successfully installed actionwebservice, version 1.1.2 Installing RDoc documentation for actionwebservice-1.1.2... D:\\development>gem install rails Attempting local installation of 'rails' Successfully installed rails, version 1.1.2
It’s pretty simple isn’t it, so now we have Ruby and Rails installed on our machine, let’s give Rails a try, and see this quick thing that everybody is talking about, we will create a rails application in our webroot folder (the one we have created in Part 1 to be our web root).
cd D:\\webroot
D:\\webroot>rails testapp
create
create app/controllers
create app/helpers
.
.
.
.
create log/production.log
create log/development.log
create log/test.log
With just this two words command we have got a complete web application hierarchy that we can start from to develop what we need, as this post is getting more longer that expected let’s just run WEBrick and see what will it look like.
WEBrick
WEBrick is a library that comes bundled with Ruby to build HTTP servers, it is commonly used as the development server for Rails applications, we will use it now to test the testapp we have just made:
D:\\webroot>cd testapp D:\\webroot\\testapp>ruby script/server => Booting WEBrick... => Rails application started on http://0.0.0.0:3000 => Ctrl-C to shutdown server; call with --help for options [2006-06-20 01:24:33] INFO WEBrick 1.3.1 [2006-06-20 01:24:33] INFO ruby 1.8.4 (2005-12-24) [i386-mswin32] [2006-06-20 01:24:33] INFO WEBrick::HTTPServer#start: pid=3668 port=3000
This will start a light webserver on port 3000, which is the default (changeable) port of WEBrick, be sure if you are running any other services that they are not using this port, how about seeing the results of two lines of work on Rails? Point your browser to http://localhost:3000 and see by yourself.

Enough for now, let’s stop WEBrick (use Ctrl+C) and install some quick gems before we configure FastCGI and Mongrel.
Extra Goodness - Ruby Libraries and Typo
Below is a quick list of some useful Ruby libraries that you may use during your development work (description taken from each project’s RubyForge page):
- RMagick: An interface to the ImageMagick and GraphicsMagick image processing libraries. Supports more than 90 image formats, including GIF, JPEG, PNG. Includes RVG, a 2D drawing API. Comprehensive HTML documentation.
to install: “gem install RMagick-win32-1.x.x-mswin32.gem” - LibXML: The Libxml-Ruby project provides Ruby language bindings for the GNOME Libxml2 XML toolkit. It is free software, released under the MIT License.
- RedCloth: A module for using Textile in Ruby. Textile is a text format. A very simple text format. Another stab at making readable text that can be converted to HTML.
- Net::SSH: Net::SSH is to SSH as Net::Telnet is to Telnet and Net::HTTP is to HTTP. Perform non-interactive SSH processing, purely from Ruby!
- Salted Login: Salted hash loging generator with ActionMailer integration
You can read the help of each library if you failed to install it via RubyGems, feel free to leave a comment here if you faced any problems during the installation.
Moving forward to install the Rails script we talked about earlier, we will install Typo, which is the first Rails Blogging system, quick, simple and widely used among Rails developers, as a start let’s download it from Typo Sphere, as you can see from Download page, it’s clearly mentioned that Typo 2.6 will not work with Rails 1.1 or above, so we have to download the version with frozen Rails included.
Unzip the downloaded file into the web root folder and let’s rename it to “blog” so we get Typo in D:\webroot\blog , now we have to prepare the required database for it, we will create a database and name it “blog” and insert the typo MySQL schema from D:\webroot\blog\db\schema.mysql.sql into it using the command line:
D:\\webroot\\blog>mysql --user=root --password
Enter password: ********
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 80 to server version: 5.0.21-community-nt
Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
mysql> CREATE DATABASE blog
-> ;
Query OK, 1 row affected (0.00 sec)
mysql> quit
Bye
D:\\webroot\\blog>mysql --user=root --password --database=blog\<"D:\\webroot\\blog\\db\\schema.mysql.sql"
Enter password: ********
Finally to get Typo working we have to update the YAML file responsible about connecting Typo to its database, this file is called database.yml and it’s located in D:\webroot\typo\config, all we have to do is changing the password line and place the password we used while installing MySQL in Part 2, then changing the production database from “typo” to “blog” (the line before last), save the file and let’s run WEBrick in production mode (from inside the blog folder) to see if we everything is fine or not yet..
D:\\webroot\\blog>ruby script/server -e=production
Pingo!! It’s running and asking us to complete our admin information, just complete it and have a look at the lovely admin panel and the Ajax goodness implemented inside, although I suggest that you just wait a little bit more to do the Apache or Mongrel integration, at least so you will be able to run it safely online even in production.

Apache2 and FastCGI
FastCGI with Apache is considered one of the best production environment for Rails applications, although there are many alternatives like LightTPD-FastCGI (Which is better), and Mongrel which will be explained here as well.
The first things we need are the mod_fcgi and mod_sql files that are available in the quick installer package named Ruby for Apache, it’s a straight forward installer that will ask you about the locations of both Apache and Ruby, which are both located in D:\development where we installed them earlier.

We don’t need the mod_ruby file (I even heard that it may make some conflicts too), so anyhow let’s choose mod_fcgi and mod_sql only and start editing our httpd.conf file to configure FastCGI.
Mainly there are three steps to configure FastCGI with Apache and all of them are in httpd.conf file that if you remember is located in D:\Development\Apache\conf\httpd.conf :
- First let’s load the FastCGI module by adding the following lines to the LoadModule section:
# Load the FastCGI module we installed through apache for ruby. LoadModule fastcgi_module modules/mod_fastcgi.so
- Secondly let’s configure FastCGI itself, preparing it for the production environment, configuring the min/max processes allowed and define the initial environment variables to lead FastCGI to the Ruby and MySQL directories.
<IfModule mod_fastcgi.c> AddHandler fastcgi-script .fcgi FastCgiConfig -maxClassProcesses 1 -maxProcesses 5 -minProcesses 1 -processSlack 1 -idle-timeout 120 \\ -initial-env PATH="d:/develo~1/ruby/bin;c:/windows/system32;c:/windows;d:/develo~1/MySQL/bin;" \\ -initial-env RUBYOPT=rubygems \\ </IfModule>
-
And finally it’s time for the VirtualHost information to be defined. Here there are two options to think of depending on your requirements and situation, for example I have an ISP that block the port 80 (as I mentioned in Part 1) so I won’t be able to run the virtual host as another subdomain referring to my server, but I have to load it on another port and make a direction later.
As I said, depending on your situation you should chose what best fits your needs, starting with the first option, we will create a new subdomain and refer it to our IP, you can do this simply by following the same steps mentioned in Part 1 for No-IP, and then at the bottom of httpd.conf we will add the VirtualHost details as follows:
<VirtualHost *> ServerName yoursubdomain.no-ip.org DocumentRoot "D:/webroot/blog/public/" ErrorLog "D:/webroot/blog/public/log/server.log" <Directory "D:/webroot/blog/public/"> Options ExecCGI FollowSymLinks AllowOverride all Allow from all Order allow,deny </Directory> </VirtualHost>The second option (which is the one I’m using currently) is where I define a new port for my rails application and then make a quick Apache redirect toward it. First we have to tell Apache to listen to the desired port, then configure the virtual host of this port to refer to our Rails application.
#Configure Apache to listen to port 4200 Listen 4200 #Defining the new virtual host at port 4200 to be our rails application <VirtualHost *:4200> DocumentRoot "D:/webroot/blog/public/" ErrorLog "D:/webroot/blog/public/log/server.log" <Directory "D:/webroot/blog/public/"> Options ExecCGI FollowSymLinks AllowOverride all Allow from all Order allow,deny </Directory> </VirtualHost>
If you created the Rails application using the “rails” command on your Win32 machine then dispatch.fcgi will automatically refer to your local Ruby file, but for ready scripts like Typo for example the referred to Ruby is the default Ruby path on Linux systems and has to be changed, to do that simply edit the first line of dispatch.fcgi (located in the “public” directory of every Rails application) from:
#!/usr/bin/env ruby
to:
#!d:/development/ruby/bin/ruby
This will tell FastCGI where your ruby bin files are located and so it will run peacefully.
Note: The above information were gathered from other websites that had solved the difficulties of integrating FastCGI with Apache like Demetrius Nunes’s “Taming FastCFI+Apache on Windows” and Scott Laird’s “Apache tuning for Rails and FastCGI” and other resources too.
Mongrel
Mongrel is very to WEBrick from it’s working point of view, although it’s much faster and more suitable for productive environments than WEBrick, it also run on a specific port and now it is well supported on Windows systems, Mongrel now can be installed as a system service which makes it more stable and better configurable.
To start working with Mongrel we have to install it along with its dependencies, gratefully using RubyGems:
D:\\development>gem install mongrel_service Attempting local installation of 'mongrel_service' Local gem file not found: mongrel_service*.gem Attempting remote installation of 'mongrel_service' Updating Gem source index for: http://gems.rubyforge.org Install required dependency gem_plugin? [Yn] y Install required dependency mongrel? [Yn] y Select which gem to install for your platform (i386-mswin32) 1. mongrel 0.3.13 (mswin32) 2. mongrel 0.3.13 (ruby) 3. mongrel 0.3.12.4 (ruby) 4. mongrel 0.3.12.4 (mswin32) 5. Cancel installation > 1 Install required dependency win32-service? [Yn] y Select which gem to install for your platform (i386-mswin32) 1. win32-service 0.5.0 (mswin32) 2. Cancel installation > 1 Successfully installed mongrel_service-0.1 Successfully installed gem_plugin-0.2.1 Successfully installed mongrel-0.3.13-mswin32 Successfully installed win32-service-0.5.0-mswin32 Installing RDoc documentation for mongrel_service-0.1... Installing RDoc documentation for gem_plugin-0.2.1... Installing RDoc documentation for mongrel-0.3.13-mswin32... Installing RDoc documentation for win32-service-0.5.0-mswin32...
Now that Mongrel is installed on our system, we have two commands that we have to use for every Rails application we have and want to run it using Mongrel, the first is where we install the service (check your Windows Services from Control Panel), to do this we have to change directory to the application we want to Mongrel it and then run the command:
cd D:\\webroot\\blog D:\\webroot\\blog>mongrel_rails service::install -N blog -c D:\\webroot\\typo -p 4000 -e production Mongrel service 'blog' installed as 'blog'.
Notice that in the above command we have specified the environment (using -e option) as production, and the port (using -p option) to be 4000 and we named the service “blog”, now the service is already installed on our Win32 system, we can run it from Control Panel -> Administrative Tools -> Services or by the command:
D:\\webroot\\blog>mongrel_rails service::start -N blog
Have a look at http://localhost:4000 now and see how it is working. You can leave Mongrel working on this specific port, or make an Apache proxy redirect to it, which is very similar to the first option we had for virtual hosts in FastCGI scenario but with two extra line:
<VirtualHost *>
ServerName yoursubdomain.no-ip.org
ProxyPass / http://localhost:4000/
ProxyPassReverse / http://localhost:4000/
ProxyPreserveHost On
</VirtualHost>
This will redirect any request to “/” which is the root of the domain to the specific port 4000 at localhost where Mongrel is already running. Note that you have to enable the mod_proxy module from LoadModule section first to get this working
More information about Mongrel on Win32 systems can be found on Mongrel official website, I know this was a very long post, much longer than the previous two parts, but at the same I couldn’t help myself from pointing up some notes and important points that might save your time while preparing this setup, I hope this was useful and helpful.
Now with the end of this part, we have our local development environment ready to host any Rails application, actually it’s already hosting Typo blogging system, using Apache2 with FastCGI or Mongrel environments for a better performance, along with PHP and MySQL that we have installed in Part 2 and No-IP that we have installed in Part 1 to allow our local webserver to go live and online. In the next part (which is the last one), Subversion will be explained and installed, allowing us to collaborate better with our colleagues and friends, creating our own repositories or even using an external one, so stay tuned and hopefully it will be shorter than this one…

Rida Al Barazi » Blog Archive » Boredom? said..
[...] As you may have seen from the date of my last post I haven’t published any new post for over two weeks now, which I should have an explanation to, and this is what I will try to do here. [...]
on July 4th at 9:49 pmAdam Craven said..
Looking forward to it :)
on August 16th at 2:16 amRida Al Barazi » Blog Archive » Rails Project Story said..
[...] Windows users: I tried my best on this: Ruby, Rails, Mongrel, FastCGI, Apache2 and Typo on Windows [...]
on August 20th at 7:54 pmJacquie said..
Hi,I followed your instruction above but got stuck when running “D:\webroot\blog>ruby script/server -e=production”. I’ve got the error message below
./script/../config/..//vendor/rails/activesupport/lib/active_support/dependencie
s.rb:207:in `load’: no such file to load — environments/=production.rb (Missing
SourceFile)
from ./script/../config/..//vendor/rails/activesupport/lib/active_suppor
t/dependencies.rb:207:in `load’
from ./script/../config/..//vendor/rails/activesupport/lib/active_suppor
t/dependencies.rb:39:in `require_or_load’
from ./script/../config/..//vendor/rails/activesupport/lib/active_suppor
t/dependencies.rb:22:in `depend_on’
from ./script/../config/..//vendor/rails/activesupport/lib/active_suppor
t/dependencies.rb:178:in `require_dependency’
from ./script/../config/environment.rb:56
from script/server:42
looks like it has something to do with the “file_name”. I updated the activesupport library but nothing seems to work. I didn’t get the result that you’ve got. would you be able to tell me where the problems are? greatly appreciated!!
on October 9th at 9:44 amJacquie said..
Now I know the problem. the command should be
on October 9th at 10:21 amruby script/server -e production without the “=” between “e” and “production”
Mike said..
gem install x doesn’t work for me, it hangs for a long time (longest I waited was 35 minutes, without any response). I downloaded all components and installed locally. Everything worked up until I started WEBrick. Well, it worked… sorta. WEBrick started, just as it appears in the tutorial, but the test page didn’t load in the browser. I tried http://localhost:3000 and http://0.0.0.0:3000 and couldn’t get the page to load. I’m a total noob when it comes to this stuff. Any ideas what could be happening?
on October 14th at 7:46 pmRida said..
@Jacquie: Welcome to ridaalbarazi.com and glad you could solve this :)
@Mike: Maybe because you are behind a NAT or something you couldn’t install the gems from remote server and you had to download them and install them locally, as for the WEBrick problem I’m not sure what’s the problem, what are getting exactly? is it a “page not found” or something else? try to start WEBrick with some other ports and check if it works.
on October 15th at 3:36 amMuhammad Babsail said..
good article its really helping me…thx
on October 16th at 7:21 pmharis ali said..
I tried to run the server in production mode i.e. ruby script/server -e=production, however it gives me the following error
C:\webroot\blog>ruby script/server -e=production
./script/../config/..//vendor/rails/activesupport/lib/active_support/dependencie
s.rb:207:in `load’: no such file to load — environments/=production.rb (Missing
SourceFile)
from ./script/../config/..//vendor/rails/activesupport/lib/active_suppor
t/dependencies.rb:207:in `load’
from ./script/../config/..//vendor/rails/activesupport/lib/active_suppor
t/dependencies.rb:39:in `require_or_load’
from ./script/../config/..//vendor/rails/activesupport/lib/active_suppor
t/dependencies.rb:22:in `depend_on’
from ./script/../config/..//vendor/rails/activesupport/lib/active_suppor
t/dependencies.rb:178:in `require_dependency’
from ./script/../config/environment.rb:56
from C:/Development/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.
rb:21:in `require’
from script/server:42
please help me I am trying to do this since the last two weeks.
Thank you so much for your help.
on February 12th at 2:51 pmRida said..
Hello Haris,
try this (note that there is no equal sign:
ruby script/server -e production
And welcome to ridaalbarazi.com
on February 12th at 3:07 pmharis ali said..
Thank so much Rida, u r the best
on February 12th at 3:43 pmpravin said..
how to resolve this error
C:\development>gem install rails –remote
on February 14th at 12:22 pmAttempting remote installation of ‘rails’
ERROR: While executing gem … (SocketError)
getaddrinfo: no address associated with hostname.
Alex Cohaniuc said..
I get this error message when I start apache with the config file modified
on March 17th at 12:44 amAlex Cohaniuc said..
I get this error message when I start apache with the config file modified:
httpd: Syntax error on line 495 of C:/development/Apache2/conf/httpd.conf: API module structure `fastcgi_module’ in file C:/development/Apache2/modules/mod_fastcgi.so is garbled - perhaps this is not an Apache module DSO?
on March 17th at 12:45 amPankaj said..
Hi Rida,
on March 21st at 1:38 pmThis is a good article.I learn many things from it.
Thanks.
trama said..
Ich erklare meinen Freunden uber diese Seite. Interessieren!
on April 11th at 3:47 pmimparare said..
Interesting comments.. :D
on April 15th at 10:00 amroger pack said..
With regard to using gems to install rails, you could also do this as
on May 11th at 3:08 amgem install rails –include-dependencies to not have to type as much :)
roger pack said..
-e=production does not work, as mentioned. Might be a nice thought to change that :)
on May 14th at 9:01 pmgerry22 said..
what happened to part 4?
on August 9th at 1:47 amRaghavendra said..
Hey things you have posted :-) pretty cool,
One simple Question triggered in my mind when i install mongrel it overlaps the webrick with default options for ruby script/server :- starts mongrel while we need to specify ‘webrick’ in options can you help me change the default behaviour and also may i know why this is so , please tell me ??
thanks in Advance
on December 27th at 12:19 pmwerutzb said..
Hi!
I would like extend my SQL experience.
I red really many SQL resources and would like to
get more about SQL for my work as db2 database manager.
What would you recommend?
Thanks,
on October 8th at 4:37 amWerutz
FeasableCase said..
Hi all! Who wants to join me on twitter. I am into celebrity gossip. Check me out on twitter. My name is Barenipples
on May 31st at 4:53 amAnnaNoble said..
I found the best thing to my sister’s birthday… It’s really hard to find cool and still unique.
on June 5th at 10:09 amSo today I saw this thing from ZTARLET on facebook where you can name a real star in the sky and have the certificate and a teddy bear sent to you and pay it by a single SMS. So awesome :)
SunnyDays said..
I’ve been watching for a while but now i’m making my first post.
Can anyone tell me their opinion of the forum thus far.
Looking to meet new people to exchange info with,so leave me your name
Bye,
virgo zodiac
on June 5th at 11:08 pmweb hosting
Oremnraparona said..
Hello,
What is the best VPS web hosting company?
I’m need to set up a web site for my supervisor.
thank you in advance,
-Francis
on June 11th at 4:26 pmCaseyFronczek said..
I saw that Casey Fronczek is offering fishing trips now down in south Florida. Does anybody have any input on these trips or has anyone been on one of these trips before?
on June 21st at 5:07 pm