Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I configure Apache 2.2 for Ruby on Rails in Windows?

I'm trying to get started writing some Ruby on Rails apps and have been successful with Mongrel but, I'd like to deploy my apps to my Apache 2.2 instance on Windows? All the tutorials I've found seem out of date and are for older versions of Apache/Rails.

Does anyone know of a good, current tutorial for configuring Apache 2.2 for Ruby on Rails apps?

like image 831
Owen Avatar asked Sep 29 '08 14:09

Owen


4 Answers

EDIT: At least until there's a Phusion Passenger for Win, Apache + Mongrel is the way to go. You can use Apache + FastCGI without Mongrel, but under real loads you will get (more) zombie processes and (more) memory leaks.

You could also look at proxying to Thin in the same way as detailed below. However, I've had some instabilities with Thin on Win, even though it's appreciably quicker. AB (Apache Benchmark) is your friend here!

Configuring Apache + Mongrel on Windows is not significantly different from *nix.

Essentially, you need to proxy requests coming into Apache to Mongrel. What this boils down to is something like this:

LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_http_module modules/mod_proxy_http.so
<VirtualHost localhost:80>
    ServerName www.myapp.comm
    DocumentRoot "C:/web/myapp/public"
    ProxyPass / http://www.myapp.com:3000/
    ProxyPassReverse / http://www.myapp.com:3000/
    ProxyPreserveHost On
</VirtualHost>

Stick this in your httpd.conf (or httpd-vhost.conf if you're including it).

It assumes you're going to run mongrel on port 3000, your Rails root is in C:\web\myapp, and you'll access the app at www.myapp.com.

To run the rails app in production mode:

mongrel_rails start -p 3000 -e production

And away you go (actually mongrel defaults to port 3000 so you could skip -p 3000 if you want).

The main difference is that you cannot daemonize mongrel on Windows (i.e. make it run in the background). Instead you can install it as a service using the mongrel_service gem.

Also, running a cluster is more complicated and you won't be able to use Capistrano. Let me know if you want more info.

like image 71
Dave Nolan Avatar answered Oct 20 '22 06:10

Dave Nolan


I'm new to RoR and have been attempting the same thing on Windows Server 2008, here are some additional notes on getting mongrel going as a service:

if you get compilation errors when installing mongrel_service:

gem install mongrel_service

try using a binary instead by specifying your platform:

gem install mongrel_service --platform x86-mswin32

Additionally, to actually install the service you need to run this command in your RoR's app directory:

mongrel_rails service::install --name MyApp -e production -p 3001 -a 0.0.0.0

(or to remove:

mongrel_rails service::remove --name MyApp

)

Then you should be able to start/stop the app "MyApp" in your windows services control panel.

Hope that helps someone.

like image 43
danny Avatar answered Oct 20 '22 06:10

danny


At the moment Mongrel does not work properly with Ruby 1.9 and will throw a "msvcrt-ruby18.dll not found" error when executing the command mongrel_rails.

Thin in this case seems to be the only option for now.

like image 2
muloka Avatar answered Oct 20 '22 06:10

muloka


I just wanted to add this article to the list. It explains how to have Apache serve ruby files without the need to install any other applications.

http://editrocket.com/articles/ruby_apache_windows.html

like image 1
aviemet Avatar answered Oct 20 '22 05:10

aviemet