WARR Installation

WARR Installation

Windows Apache Ruby Rails

(plus php, Mysql, and phpMyAdmin)

Setting up Ruby on a Windows machine is pretty darn easy. However, adding rails, and getting it all to work through apache 2.x is not. Or, at least, I couldn’t find a single resource that would help walk a neophyte through the whole process. That’s what this post is all about. If you happen to find anything wrong with this write-up or have any handy tips – please let me know in the comments.

The steps that follow assume only one thing: Your not afraid to try things. My computer had none of the stuff installed when I started and I spent a good part of five hours figuring all of this out and getting everything to work perfectly. Hopefully, this summary, will help you avoid some of the same snags I hit. Plus, it will be here should I ever have to go through it all again.

Before we move forward I want to make a couple of suggestions that might help you keep things more organized. Let’s use some good directory names to help manage all of this stuff; tools, websites, downloads. We will be installing things in tools, building websites in “websites” and downloading our files into “downloads”. Each of these three directories will exist under one additional directory, “dev” which stands for development. So you will have a structure like this:

  • C:\
    • dev
      • downloads
      • tools
      • websites

I will reference these directories throughout this manual. Plus, they will make it easier when messing around with the command line later.

Be forewarned, this is a long post. In fact, it’s more like a manual. So here is a table of contents

Table Of Contents

  1. What You Need
  2. Required Installation
  3. Optional Installs that May Help
  4. Creating a Rails Application
    • Rails and Apache
      • Apache httpd.conf and virtualhosts
      • Windows hosts file

What you Need

Before you can install anything you need to download it. Here is all the stuff you need, or might need. You don’t need the PHP stuff, but I list it because I’m familiar with phpMyAdmin and it is pretty much the only tool I have ever used for administering MySQL. If you have another tool, or are comfortable using the command line, then just skip the PHP and phpMyAdmin stuff.

Required Items
  1. Ruby One Click Installer – grab the latest stable version.
  2. Apache Webserver 2.x – download the Windows MSI Binary Installer of the “best available version”
  3. Rails a Ruby Framework – we will talk more about this later. It is installed via a built in Ruby tool called “Gems”
  4. RubyForApache – ModRuby and FastCGI installation helper; get the newest version. We will talk more about this later too.
  5. MySQL this is your database.
Optional Stuff
  1. php – i suggest the latest stable version. Get the zip package and NOT the installer.
  2. phpMyAdmin – grab the latest version. This will make your life with MySQL easier.

table of contents

Required Installation

Installing Apache

When you begin the install, accept the license, fill out the server information (i used localhost, localhost, myemail, all users on port 80 as a service). Next pick the custom install option. Now you can click the “change” button and change your path to c:\dev\tools. The installer will create an “Apache2″ directory under your tools directory. I don’t change any of the other settings so hit next then “install”. The apache installer will do it’s magic and you’ll be good to go; for now. Once the installation completes you will have a new item in your tray for the apache monitor. Open your browser and enter the address “http://localhost” to see if it worked.
Go into httpd.conf and uncomment out the line:

	LoadModule rewrite_module modules/mod_rewrite.so
Setting Up Ruby

This is pretty easy too thanks to the “one click installer” just launch it and when it asks for your path enter “c:\dev\tools\ruby”. The installer will do its magic. The trick comes with tying Ruby and apache together.

table of contents

Installing MySQL

This is pretty easy too just run the installer, when it asks where to install too tell it c:\dev\tools and voila.

table of contents

Getting Rails

Open a command window, change directory to c:\dev\tools\ruby\bin then type:
gem install rails
If it prompts you on what to do with dependancies, hit “y” and enter for each to get all of them. This takes a while but when it is done your almost ready to go!

table of contents

Installing RubyForApache

Again, you just need to launch the installer. This time though you need to provide the right path for rubyforapache “c:\dev\tools\ruby4apache”, apache “c:\dev\tools\apache2″, and Ruby “c:\dev\tools\ruby”. However, after this one finishes installing we have to do a few manual steps. First open up c:\dev\tools\apache2\conf\httpd.conf and add

     LoadModule fastcgi_module modules/mod_fastcgi.so
     LoadModule ruby_module modules/mod_ruby.so

to the end of your LoadModule section then add

     <IfModule mod_fastcgi.c>
       AddHandler fastcgi-script .fcgi
     </IfModule>

     <IfModule mod_ruby.c>
       # for Apache::RubyRun
       RubyRequire apache/ruby-run

       # exec files under /ruby as Ruby scripts.
       <Location /ruby>
         SetHandler ruby-object
         RubyHandler Apache::RubyRun.instance
         Options +ExecCGI
       </Location>

       # exec *.rbx as Ruby scripts.
       <Files *.rbx>
         SetHandler ruby-object
         RubyHandler Apache::RubyRun.instance
       </Files>
     </IfModule>

to the bottom of the file just before the Virtual Hosts section. Next restart the apache service. If Apache won’t restart just reboot your machine and it should be fine.

If Apache still won’t restart you are probably getting entries in your Event Log for “Applications” similar to the following:

Cannot load C:/dev/tools/Apache2/modules/mod_ruby.so into server: The specified module could not be found
Syntax error on line 176 of C:/dev/tools/Apache2/conf/httpd.conf:

To resolve this make sure the path to your Ruby install “bin” directory is in your system path. In the example I have provided so far you need to append “;c:\dev\tools\ruby\bin” to the end of your current path. I am using windows XP Pro. In order to modify my path I had to right click on “My Computer” choose “Properties” and from the dropdown menu. A dialog window should appear. I then clicked on the advanced tab; the environmental variables button, and in the system variables section I scrolled down until I found “path”, click edit, add the suggested text to the end, click OK. click OK again, then restart for the change to take affect.

table of contents

Optional Installs That May Help

Installing PHP

Installing PHP is really easy. Just extract the zip file you downloaded to c:\dev\tools\php.

php.ini

Then open up the file c:\php.ini-dist and update the following lines:

  • include_path = “.;c:\dev\tools\php\includes” (line 436) basically we updated the value and uncommented (removed the preceding semicolon)
  • extension_dir = “c:\dev\tools\php” (line 451) just an update of the value
  • extension=php_mysql.dll (line 578) we just uncommented this line (removed the preceding semicolon)

then save this file in the c:\winnt directory.

MySQL Connectivity

While your at it copy the file c:\dev\tools\libmysql.dll to the c:\winnt\system32 directory. This will make it so that your PHP files can talk to your MySQL databases.

PHP and Apache

Finally, you need to configure apache to work with PHP. To do that we need to edit the file c:\dev\tools\apache\conf\httpd.conf and add/edit the following lines:

add this line after all of the other LoadModule commands.
LoadModule php5_module “c:/dev/tools/php/php5apache2.dll”
add this value to the line with setting “DirectoryIndex”
index.php
finally add this line after the other AddType commands.
AddType application/x-httpd-php .php

table of contents

Creating a Rails App

change to the c:\dev\websites directory and then, at a command prompt enter:
Rails appname

Rails and Apache
.htaccess

Now, go into the c:\dev\websites\appname\public directory and edit the file .htaccess changing the RewriteRule and RewriteBase
instructions.

RewriteEngine On
RewriteRule ^$ index.html [QSA]
RewriteRule ^([^.]+)$ $1.html [QSA]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ dispatch.fcgi [QSA,L]
RewriteBase /dispatch.fcgi

Now open dispatch.cgi, dispatch.fcgi, and dispatch.rb and make sure the first line looks like:
#!c:/dev/tools/ruby/bin/rubyw.exe
Honestly, I dont know what the difference is between Ruby and rubyw.exe – and the app will work either way.

Apache httpd.conf and virtualhosts

Next, go into your c:\dev\tools\apache2\conf\httpd.conf file and jump to the bottom of it

Once there find the line:

	#NameVirtualHost *:80

and change it to

	NameVirtualHost 127.0.0.1:80

(notice we also uncommented it.)
Now you also need to add some virtual hosts. Since you will still want to have access to localhost we need
to add at least 2 virtual hosts when you make your first Ruby site:

	<VirtualHost 127.0.0.1>
		ServerAdmin admin@localhost
		DocumentRoot "C:/PROGRA~1/APACHE~1/Apache2/htdocs"
		ServerName localhost
		ErrorLog logs/localhost_error.log
		CustomLog logs/localhost_access.log common
	</VirtualHost>

	<VirtualHost 127.0.0.1>
		DocumentRoot "c:/rubyweb/todo/public"
		ServerName todo
		ServerAlias *.todo
		ErrorLog c:/rubyweb/todo/log/server.log
		<Directory "c:/rubyweb/todo/public">
			  Options ExecCGI FollowSymLinks
			  AllowOverride all
			  Allow from all
			  Order allow,deny
		</Directory>
	</VirtualHost>

Note that in the second virtual host I’m referencing a Rails app named todo. You can change the servername and the directories to match your scenario. We are almost done.

Windows Hosts File

Now go to c:\winnnt\system32\drivers\etc and open the hosts file. In it we need to add a line for each virtualhost you create. localhost should already be there but if not add it like so:

127.0.0.1	localhost
127.0.0.1	todo

You could also just have

127.0.0.1	localhost todo

table of contents