Configuring the Apache Web Server to Run Ruby on Windows

Listed below is information on how to configure the Apache web server to run Ruby programs on Windows machines. For information on installing and configuring Apache for Windows, please see the following:

Installing and Configuring Apache for Windows

For information on configuring Apache to run other programming languages such as Perl, PHP, and Python, please see the following links:

PHP for Windows

Python for Windows

Ruby for Windows

 

1. Install Ruby

You can get Ruby from the following: http://rubyinstaller.org/. Simply click the link for the one-click windows installer and select the latest stable release. Download the file and launch the installer. When asked, go ahead and put check marks next to all of the components to install. Everything else can remain as the defaults.

 

2. Configure Apache to run Ruby CGI

The next step is to use EditRocket to open the httpd.conf apache configuration file located in the apache install directory in the conf directory. Search the httpd.conf file for the line

Options Indexes FollowSymLinks

Add ExecCGI to this line. The line should now look similar to the following (NOTE: there may be more options listed):

Options Indexes FollowSymLinks ExecCGI

Next, search for the following:

#AddHandler cgi-script .cgi

Uncomment this line by removing the # in front of the line, and add a .rb to the end of the line. The new line should look like this:

AddHandler cgi-script .cgi .rb

3. Restart Apache

Now, the apache web server needs to be restarted. You can do this either via the Apache service located in the services control panel or via the Start -> All Programs -> Apache . . . -> Control Apache Server menu option.

4. Run a test Ruby page

You can use the EditRocket sample web page Ruby template for a test Ruby page. This is located in File -> New From Template -> ruby -> Sample_Web_Page. The following is an example of the template:

#!/usr/bin/ruby
puts "Content-type: text/html"
puts ""
puts "<html>"
puts "<body>"
puts "Test Ruby Page."
puts "</body>"
puts "</html>"

Note the line #!/usr/bin/ruby. This line needs changed to match the location of your Ruby installation. For example,

#!/ruby/bin/ruby

Here is an example assuming Ruby is installed in the C:\Ruby location

#!/ruby/bin/ruby
puts "Content-type: text/html"
puts ""
puts "<html>"
puts "<body>"
puts "Test Ruby Page."
puts "</body>"
puts "</html>"

Save this file as test.rb to your htdocs folder under your apache installation directory. Open your web browser and type in your apache host (and :port if the port is something other than 80) followed by test.rb, for example

http://localhost/test.rb