What happens when Windows is the step-child? Adventures in Ruby on Rails.
Like many of you I’ve heard the developer community going on about Rails for quite a while now. It wasn’t until recently I had any reason to dip into that world. Over at Nitosphere the website is all run on Rails. We got a inexpensive web host and it was pretty easy to get it up and running. Like most shared web host, it is all linux/open source based. We have now grown to the point that hosting our own server would be cheap enough and give us complete control over the box. As a Microsoft ISV I thought it would be nice to have our new box be a Windows box. It would also be nice to hook in to SQL Server instead of MySQL as well. After a little digging I did find that Microsoft is sponsoring IronRuby, a Ruby clone that runs on the .net platform. Unfortunately, it isn’t completely compatible with one of the packages that we need to run the website on. So, back to Ruby. There is also a gem to run Rails apps against SQL Server, It isn’t compatible with some of the stuff on our website ether. Finally, I fell back to ODBC to connect to SQL Server. Everything wired up but there was still an incompatibility issue. I’ll keep trying to work it out but our fall back was MySQL.
You will need:
If you plan on getting the source for anything you will need ether GIT or Subversion.
GIT for windows:
http://www.sliksvn.com/en/download/ basic client 32bit or 64bit
some folks prefer tortoisesvn
Ruby 1.8.7 has the most compatibility with existing gems. Get the latest installer if the one linked isn’t it. There are installers for 1.8.6 and 1.9.1. Again, check to see if they will support the gems you will need to get your site up and running!
install the dev kit if you would like to compile some gems instead of manually downloading them. If you don’t install the devkit some gems will fail to install since they can’t compile to a native extension. To get around that you can also use –platform=mswin32 when you install a gem.
Example: gem install fastercsv –platform=mswin32 will fetch the precompiled windows gem if it exists. for more information on the devkit check out this link. http://www.akitaonrails.com/2008/7/26/still-playing-with-ruby-on-windows
By default when you create an application Ruby on Rails defaults to sqlite3. If you want to use Sqlite3 you will need to download the dll’s and the command line executable.
Since I couldn’t get our site to talk to SQL Server we are staying on MySQL for now. You can use the latest installer 64 bit or 32 bit but you must have the 32 bit library for Ruby to work properly. The libmySQL.dll from the 5.0.15 install did the trick for me.
If you would like to try the SQL Server adapter just do a gem install activerecord-sqlserver-adapter to get it.
HTTP Ruby Server:
I went with mongrel, it may not be the best but it was pretty easy to setup and get up and running. I am running version 1.1.5 right now since that seems to work best with mongrel_service which you will need if you don’t want to stay logged into your web server with a dos prompt running. I opted for the latest beta of mongrel_service since it cut out some dependencies and seems pretty stable at the moment. As always adding –pre gets the latest beta gem. Also, –include-dependencies will grab everything the gem will need to run, including mongrel.
Gems specific to my install:
Substruct uses rmagick for thumbnail generation, which requires image magic to do the actual work.
Redcloth is a textile markup language for Ruby. If you didn’t install the devkit don’t for get to add –platform=mswin32 to your gem install commands.
My installation steps:
Make sure c:rubybin (or where you installed it to) is in the path. I recommend a path with no spaces so no c:program files.
extract the devkit to the c:ruby directory.
extract the sqlite exe and dlls to c:rubybin
extract libmySQL.dll from the 32 bit 5.0.15 archive
Open an command prompt with administrator privileges.
Issue these commands:
gem update –system
gem install rails –no-ri –no-rdoc
gem install sqlite3-ruby –no-ri –no-rdoc
gem install mysql –no-ri –no-rdoc
gem install mongrel_service –no-ri –no-rdoc –platform mswin32 –include-dependencies –pre
After that install any gems you need for your Rails app. Make sure and test that your app works in production mode with mongrel before anything else. There will be some kinks to work out I’m sure. Once you are happy that everything is running as expected you can install your mongrel service.
mongrel_rails service::install -N MyAppsServiceName -c c:appmyapp -p 3000 -e production
The –N is the service name. –c is where the app will be served from. –p is the port number that it will listen on. –e is the mode it will run in like development or production. I chose a few high ports 3000 to 3008 for my services to run in.
You can always remove a service if something is wrong.
mongrel_rails service::remove -N MyAppsServiceName
Setting up IIS7:
Install the application request routing 2.0 and URL Rewrite plug-ins using the Web Platform Installer
Once that is done you will need to create a new web farm.
Next you will need to add at least one server entry. You may want to edit your host file and add additional aliases to your IP Address so you can run multiple copies of mongrel to service all request. The recommendation is one per cpu/core.
The last step the wizard ask if you want to add the routing rules. The answer is yes.
You can confirm the routing rules are in place.
Make sure you have a website in IIS running and listening on port 80. Without this there is nothing for IIS to route to your new server farm.
If you have any questions post them up. I’m not a Rails expert but I have just been through the pain of Rails on Windows!