Thursday, May 11, 2006

What does Rails on Apache mean?

Assuming you have a running rails application on WEBrick (which comes with rails), its 5 mins job to have rails up and running on Apache. You will need following things.
Remember You do not need FastCGI at all to run rails on Apache. .

Every rails application created is Apache deployable ready (that sounds so good!!), you don't need anything extra, neither FastCGI or Mongrel. You will need these 2 puppies for some other reasons that I will point out soon.

# Apache HTTP server
# Rails application

2 step process

- Open Apache httpd.conf under /conf.
- Add following at the very end and restart Apache

Listen 8027
<VirtualHost 127.0.0.1:8027>

DocumentRoot [railsapppath]/public/
<Directory [railsapppath]/public/>
Options ExecCGI FollowSymLinks
AddHandler cgi-script .cgi
AllowOverride all
Allow from all
Order allow,deny
</Directory>
</VirtualHost>

Or another better way is to (Use Apache Alias technique) add following in your httpd.conf

Alias /railsappname [railsapppath]/public


<Directory [railsapppath]/public>

Options ExecCGI FollowSymLinks

AllowOverride all

Order allow,deny

Allow from all


</Directory>

- Open public/.htaccess file and add "RewriteBase /railsappname "

(With above technique you will not be creating virtual host on different port and this kind of setup makes more sense when you have more than one rails component sitting on Apache)


Here

[railsapppath]/public/: is your rails application public folder. You need to point to this directory, else it won't work.

Port 8027: some random port, on which you are asking Apache to run a virtual host for your rails application.

Now just point your browser to http://127.0.0.1:8007/ and you will see the rails running on Apache. How fast was that?. Oh did I ask How fast was that?. Yes now this takes us to our next topic

# Fast CGI: Fast CGI makes ruby run faster on Apache, otherwise by itself ruby is slow on Apache, because it runs native CGI. I will talk on this in detail, in my next blog topic

# Mongrel : This puppy is getting its traction. Right now working good in Linux and Windows, not so good for Mac OSX. But this one is supposed to be better than FastCGI. I still need to experiment that.

4 comments:

Anonymous said...

Looks nice! Awesome content. Good job guys.
»

Anonymous said...

Very best site. Keep working. Will return in the near future.
»

Anonymous said...

I find some information here.

Anonymous said...

Here are some latest links to sites where I found some information: http://google-index.info/2851.html or http://neveo.info/2271.html