Monday, April 4, 2011

Installing Windows Server 2008 EE with Ruby on Rails and LDAP (Part Three)

Installing Windows Server 2008 EE with Ruby on Rails and LDAP (Part Three)

In Part Two, we successfully installed Apache and Ruby.  In this part, we’re going to focus on Rails, some gem dependencies for our application, and decide on our database and web server in rails.  Once done, I’m going to try to work on some additional configuration for our server. So, with that said, let’s start with installing Rails.  

First, there are two choices we can make here.  We can install the latest version of Rails, or install the latest version of EDGE rails; the latter being the cutting edge of rails development. Because my goal here is working with LDAP authentication and functionality, I’m going to stick with the very basics.  Let’s start.

=> gem install rails

As you can see, rails installed a lot of core dependencies here.  Now, I want to make things simple in terms of where my app is going to launch.  So, I’ll create a directory called Web in the root of C:\ and place my new application in there.

C:\>md web
C:\Web>rails new ldap

Good.  I now have a new application for rails called ldap located in C:\Web\ldap.

I’m also going to have to install the DevKit properly in case any gems need to be built on Windows Server 2008.  I already have the development kit downloaded, so I’m going to extract it into a directory called:


Once extracted, I need to go to that directory and type the following commands:

=> ruby dk.rb init
=> ruby dk.rb install

The init command creates a .yml (YAML) file that houses the directories on the server where ruby is installed.  By default it knows that Ruby192 was already listed in C:\ and so no modification was necessary.  Once I ran the install, it created some enhancements in the existing ruby directory for C:\Ruby192.

If you need to see more instructions about the DevKit, you can go here:

The Database

Rails already comes with a default database called SQLite3.  Because this is a simple test application, I’m going to keep this default.  However, Windows Server 2008 doesn’t know what this is.  You still need to download the .dll library.  You can find it here:

I only need the .dll so I’ll install that in downloads and then extract and move the .dll into my C:\Ruby192\bin directory.  This directory is already added to my system path, so it’ll find it just fine.

I’ll modify the gem file and take a peek and for now, everything is exactly what I need. There’s nothing I need to do here until later.  Let’s go ahead and test whether or not we have a basic functioning rails app.

C:\Web\ldap\>bundle install
C:\Web\ldap\>rails s

Bundling will make sure any gems, and dependencies I need are installed and once complete,rails s will start the server.  Once the server starts (using a generic webrick server), let’s go to http://localhost:3000 (in my case) and take a look:

Great!  It’s working.  We’re riding Ruby on Rails on Windows Server 2008.  No time to pat myself on the back yet, I still have quite a few things left to do here.  Let’s get to work!

I want to get thin installed, but unfortunately on Windows, thin (which requires rack and eventmachine) can be a pain in the butt to install.  However, there’s a great work around we can do on Windows to get this installed and it partly uses “Git” to accomplish this task.   I’ll eventually be using Git anyways later on to backup my source code, so I’ll just go grab a copy of it from here:

When I install it, I want to include the git bash here and git gui here context menu entries and also make sure you choose “as is” on the following screen so you don’t get the CRLF issues when pushing your source files later on.

Now then, I have Git successfully installed, but before I do anything I’ll need another gem called specific_install.  From a windows command prompt type the following:

=> gem install specific_install

Now that I have this gem installed, I’ll right-click anywhere on a directory in windows explorer (and choose git bash here).

Run gitbash and type:

=> gem specific_install -l git://

This should install the latest beta or latest eventmachine file, which is required by Thin to operate.  Rack already came with the latest version of rails, so nothing is needed here.  You might be saying whoa!! Why aren’t you just using the Developer Kit and compiling eventmachine.  Well, on windows server 2008 64-bit, that’s not going to work.  I will get a compile error with eventmachine only.  Now then, once downloaded  let’s run (from the windows command line):

=> gem install thin

Great, it installs just fine!  Let’s try running it: (using the command rails s thin)

And, let’s open a web browser and see what happens:

.. yay, it’s working. 

So, the one thing that people may complain about with Ruby and Ruby on Rails is that setting things up is no easy task on Windows.  This is primarily why most people that develop with Rails tend to use Linux or Mac, and even Mac can run into its own complexities.   With Windows however, you have to remain calm and be patient throughout the installation process.  Before we continue, let’s recap what we have accomplished so far:

  • Installed and configured Windows 2008 Server EE (64 bit) with Active Directory as its primary role (although AD is not currently configured)
  • Installed Apache 2.x (as our load balancer) (still needs configuration)
  • Installed Ruby 1.9.2(p180)
  • Installed the Ruby Development Kit
  • Installed Ruby on Rails v. 3.0.5
  • Configured Sqlite3 as our database
  • Installed THIN as our fast HTTP Web Server
  • .. and tested that it works for the most part.

That's a pretty big list already!  So, before we move on, let’s take a break and rest and come back tomorrow and continue with our setup.  See you in part four..

No comments:

Post a Comment