My Project Blog


Setting up Ruby on Rails with WAMP
November 24, 2008, 6:22 pm
Filed under: Uncategorized | Tags: , ,

Alright.  Let’s get back to business.  There are some AS3 frameworks out there for MVC (PureMVC, Cairngorm…).  Looked into them but i rather have something more flexible, more transparent and not AS3.  So, RoR backend and Flash front end seems to be a good mix.

To set up RoR on the WAMP server.

Check out the following forum thread,

http://forum.stylegala.com/viewtopic.php?t=3964

The thread was posted on eons ago, so here is the updated stuff.  The new stuff is in red.

……

Things you will need:

1. Wampserver (Prepackaged Apache 2, PHP, phpMyAdmin, MySQL) – http://www.wampserver.com/en/index.php <the version i used was 2.2.8>
2. Ruby “One-Click” Installer for Windows – http://rubyforge.org/frs/?group_id=167 <latest version>
3. Ruby Gems for Windows (Similar to PEAR) – http://rubyforge.org/frs/?group_id=126 <latest version>
4. Ruby For Apache – http://rubyforge.org/projects/rubyforapache/ <the discontinued version>

<There is project called Instant Rails, google it, it has everything mentioned above packaged into one bundle of goodies.   But, i only learn thru the hard way and transparency. >

Step By Step Process:

First and foremost, I have used many servers for my development environment, but none have compared to WAMP. It allows you to easily flip Apache modules / PHP extensions on and off, not to mention switch between PHP 4 and PHP 5, all with an unintrusive GUI. There are quite a few plug-ins such as Zend Optimizer, Webalizer, Perl, etc. The best part is that WAMP is FREE. (although donations are welcome, which I myself have been rallying my organization to contribute to the project).

Keep in mind that for my entire example, wamp is setup on my D:\wamp drive / path. As you are following these instructions, substitute your drive / path. I will remind you periodically to substitute your drive / path. It is imparitive you pay attention, and follow these instructions verbatim. Do not skip ahead! (unless told to do so)

Step 1 – Install Wampserver (#1 of “Things you will need”)

– If you already have WAMP installed, continue to Step 2

Step 2 – Install Ruby (#2 of “Things you will need”)

– When the application starts, it will ask you if you want to install SciTE and FreeRIDE; These are not required
– I installed ruby alongside my php directories under D:\wamp, so the end path will be D:\wamp\ruby
– Click “Install”

Step 3 – Install Ruby Gems (#3 of “Things you will need”)

– Extract the contents of your Ruby Gems to D:\wamp\ruby\rubygems
– Open a DOS prompt window, and enter the following commands:


> D:
> cd D:\wamp\ruby\rubygems
> setup

– Note: keep in mind your wamp drive / path
– If all went well, you should see the following (or similar):


Successfully built RubyGem
Name: sources
Version: 0.0.1
File: sources-0.0.1.gem

Step 4 – Install Rails

– Open a DOS prompt window, and enter the following commands:


> D:
> cd D:\wamp\ruby\rubygems
> gem install rails --include-dependencies

– Be patient… gems is downloading rails from rubyforge.org
– Again, if all went well, you should have seen commands executing, with a final note indicating


Installing RDoc documentation for activerecord-1.14.4...
Installing RDoc documentation for actionpack-1.12.5...
Installing RDoc documentation for actionmailer-1.2.5...
Installing RDoc documentation for actionwebservice-1.1.6...

– Keep in mind that there will be more statements than what I included above.

Step 5 – Install Ruby For Apache (#4 of “Things you will need”)

– I installed Ruby for Apache in my D:\wamp\ruby\RubyForApache subdirectory
– Locate your Apache server directory, in my case, its D:\wamp\Apache2 (keep in mind that the application for whatever reason tries to append “RubyForApache” to the path. Simply make the path “D:\wamp\Apache2” (or where your root Apache directory is located))

< for my version of WAMP, the apache folder is under c:\wamp\bin\apache\…>

– Next, locate your root ruby directory, which is D:\wamp\ruby for me. Again, remove the “RubyForApache” from the “D:wamp\ruby” path (see above).
– Finally, for the Installation Options, uncheck all options but “mod_fastcgi”
– Note: The application may alert you that it cannot open c:\xppro\system32\msvcp71.dll. Just rename it and retry. As I’m writing this documentation, I didn’t have an issue, but had noticed it on a previous install.

<had the same issue with msvcp71.dll, rename it and installer should run fine>

Step 6 – Setup Apache

– After the Ruby For Apache is installed, you will notice ‘mod_fastcgi.so’ in your D:\wamp\Apache2\modules folder
– Next, move to D:\wamp\Apache2\config directory and open ‘httpd.conf’
– After the LoadModules section, append the following code:


LoadModule fastcgi_module modules/mod_fastcgi.so
<this did not work with my version of Apache, someone on the thread found a new DLL to use.  Google FCGI and download mod_fastcgi-2.4.6-AP22.dll and put it in a <DIR>>
<IfModule>
FastCgiConfig -maxClassProcesses 10 -maxProcesses 10 -minProcesses 1 -processSlack 1 \
-initial-env PATH="d:/wamp/ruby/bin;c:/windows/system32;c:/windows;d:/wamp/mysql/bin/"  \
-initial-env RUBYOPT=rubygems
AddHandler fastcgi-script .fcgi .fpl
</IfModule>

<here is my code in my httpd.conf

LoadModule fastcgi_module “c:/wamp/bin/apache/apache2.2.8/fastcgi/mod_fastcgi-2.4.6-AP22.dll”

<IfModule fastcgi_module>
FastCgiConfig -maxClassProcesses 10 -maxProcesses 10 -minProcesses 1 -processSlack 1 \
-initial-env PATH=”c:/wamp/ruby/bin;c:/windows/system32;c:/windows;c:/wamp/bin/mysql/mysql5.0.51b/bin/”  \
-initial-env RUBYOPT=rubygems
AddHandler fastcgi-script .fcgi .fpl
</IfModule>

>

Step 7 – Install your first Rails App

– If you have a “work” directory for Ruby projects, change to that directory. Open a DOS prompt window, and enter the following commands:


> D:
> cd D:\wamp\www\projects\RUBY
> rails test

– This creates your first rails application in D:/wamp/www/projects/RUBY/test
– Note: your “projects\RUBY\” directory may differ. Simply substitute your path as needed.

Step 8 – Modify your “test” install’s “public/.htaccess” file

– Navigate to your D:\wamp\www\projects\test\public\ folder and open the .htaccess file
– Look for:

<if you don't have a .htaccess, i stole one from the README file in the apache dir and made the necessary hacks

# General Apache options
#AddHandler fastcgi-script .fcgi
#AddHandler cgi-script .cgi
Options +FollowSymLinks +ExecCGI

# If you don’t want Rails to look in certain directories,
# use the following rewrite rules so that Apache won’t rewrite certain requests
#
# Example:
#   RewriteCond %{REQUEST_URI} ^/notrails.*
#   RewriteRule .* – [L]

# Redirect all requests not available on the filesystem to Rails
# By default the cgi dispatcher is used which is very slow
#
# For better performance replace the dispatcher with the fastcgi one
#
# Example:
#   RewriteRule ^(.*)$ dispatch.fcgi [QSA,L]
RewriteEngine On

# If your Rails application is accessed via an Alias directive,
# then you MUST also set the RewriteBase in this htaccess file.
#
# Example:
#   Alias /myrailsapp /path/to/myrailsapp/public
#   RewriteBase /myrailsapp

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

# In case Rails experiences terminal errors
# Instead of displaying this message you can supply a file here which will be rendered instead
#
# Example:
#   ErrorDocument 500 /500.html

ErrorDocument 500 “<h2>Application error</h2>Rails application failed to start properly”

>

<REMEMBER, you need to allow override in your httpd.conf file!!!  The default setting for AllowOverride.  Default is “AllowOverride None”, i set it to “AllowOverride All”.  I am still playing around with Apache, so i need to look into what is the best parameter to set, but “All” works.>

# General Apache options
AddHandler fastcgi-script .fcgi
AddHandler cgi-script .cgi
Options +FollowSymLinks +ExecCGI

– And change to:


# General Apache options
# AddHandler fastcgi-script .fcgi
# AddHandler cgi-script .cgi
Options +FollowSymLinks +ExecCGI

– We do this because we’ve already defined the handlers in step 6.
– Next, look for:


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

– And change to (change .cgi extension to .fcgi):


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

– Save and close the file

Step 9 – You are almost done. One last change to the “public/dispatch.fcgi” file

– Navigate to your D:\wamp\www\projects\test\public\ folder and open the dispatch.fcgi file
– Change the #! (shebang – line #1) at the top of the file to reflect the path to the Ruby interpreter (where its located on your system). I had to change mine to:


#!D:/wamp/ruby/bin/ruby

– Note: Your path may differ. If you don’t remember the ruby intepreter’s path, refer to Step 2.
– Save and close the file

….

Enjoy!!!