Ubuntu Hardy - using mod_rails to serve your application
Following from the first article, we now have passenger (mod_rails) installed.
As such, we can move on and create a Ruby on Rails application and see how easy it is to serve using passenger.
Rails application
Move into the public_html folder (if you don't have one, then simply create it):
cd ~/public_html
Then create a simple Ruby on Rails application:
rails testapp
Done.
Virtual Host
To serve the Rails application, we need to create a virtual host:
sudo nano /etc/apache2/sites-available/testapp
Although already mentioned, one of the exciting things about mod_rails is that you don't need any special settings in the virtual host configuration.
The contents can be as simple as this:
<VirtualHost *:80>
ServerName domain1.com
ServerAlias www.domain1.com
DocumentRoot /home/demo/public_html/testapp/public
</VirtualHost>
Of course, you can add custom log file locations and other settings but the main thing to understand is the lack of proxy and port settings.
Once done, we can enable the new site:
sudo a2ensite testapp
Rewrite
As you may know, Rails applications make use of an .htaccess file for various rewrite rules.
If this is a fresh Slice and you do not have the Apache rewrite module enabled, now would be a good time to enable it:
sudo a2enmod rewrite
Reload
Finally, reload Apache:
sudo /etc/init.d/apache2 reload
Note: If you get any port and NameVirtualHost errors on reloading Apache, please ensure you read the Apache Virtual Hosts article.
Done.
Is that it?
Yup. It really is that simple to serve Ruby on Rails applications with passenger (mod_rails).
Additional Rails apps can be configured in the same way - create a vhost and it's done.
Changes to the application
Whenever you deploy changes to your application all you need to do to is:
touch /home/demo/public_html/testapp/tmp/restart.txt
That will enable the new content to be served - the command can be used in Capistrano or any script you use to deploy your applications.
Summary
Phusion's passenger (mod_rails) is easy to install and even easier to use.
There are no ports or proxies or any other complicated configurations.
Although it is relatively new, mod_rails offers a great deal to the Ruby on Rails community.
PickledOnion


Article Comments:
PeterG commented Thu May 01 20:41:22 UTC 2008 ago:
I have an existing rails app running in hardy using apache2 mongrel etc
Can it hurt to simple redeploy using passenger using this article protocols
PickledOnion commented Fri May 02 09:18:48 UTC 2008 ago:
Peter,
I don't see why that would be an issue.
I would create a new vhost so you could quickly pop back to the mongrel setup if required and then disable the old one and enable the new one.
In theory it should be straight forward....
PickledOnion
Rodrigo commented Fri May 02 14:12:12 UTC 2008 ago:
What about memory usage (specially in a 256mb slice)? mod_rails' default configuration seems to spawn up to 20 instances of the application if requested, and that would cripple the slice... maybe you should recommend tweaking the RailsMaxPoolSize option according to the slice size. Or am I undestanding this the wrond way?
PickledOnion commented Fri May 02 14:14:44 UTC 2008 ago:
Hi,
I would always recommend adjusting any installation to your site and Slice needs.
I have been using mod_rails for a few hours and haven't seen any issues with memory but as I say, you will always need to optimise anything you install.
PickledOnion
fractious commented Fri May 02 17:11:45 UTC 2008 ago:
Thanks for taking the time to post this Pickled. Any tips you can give on how to go about optimising RailsMaxPoolSize for best performance would be a great addition :)
PickledOnion commented Fri May 02 17:13:49 UTC 2008 ago:
Hi,
After Rodrigo's comment and yours I think I will do a follow up article going through the various options.
I must admit I've not put it under any sort of load but I'll see what I can come up with :)
PickledOnion
fractious commented Fri May 02 17:23:14 UTC 2008 ago:
Nice one. Looking forward to it.
PeterG commented Sat May 03 04:45:05 UTC 2008 ago:
ok I finally got my 2 websites up and served by passenger using rails. did free -m mem total 256 used 187 free 69
get this
Each website has ONE index.html page with exactly 10 characters
This is using sqlite3 and mysql is not even installed yet.
And i followed the hardy instructions from page one on a new install. ??????? not being critical here I am just stating the facts man just the facts.
As simple as passenger may be I would also prefer an apache mongrel mysql tutorial before something that as yet is unproven. Keep up the good work this is great stuff.
PickledOnion commented Sat May 03 12:03:38 UTC 2008 ago:
Hi Peter,
Not really sure what your point is?
You have two Ruby on Rails applications up and running on a 256 Slice with memory to spare..
You can't serve a site with one mongrel (not if you want more than 1 visitor at a time anyway) so you would need 4 mongrels to serve the 2 sites. A 256 cannot handle 4 mongrels when under load. It is something we see all the time and reducing the mongrels to 3 allows a 256 to work within parameters.
Sure, this is new stuff but I honestly don't see what your point is?
PickledOnion
Ken commented Mon May 05 16:09:42 UTC 2008 ago:
Hi PickledOnion,
Thanks for this and all the other great work you've done. I'm curious - if we're using mod_rails what is the impact on deployments? What do we need to adjust from the Capistrano side? FYI, I would also like to see an article laying out the traditional mongrel/MySQL setup.
Thanks, Ken
Dave commented Tue May 06 02:48:28 UTC 2008 ago:
I'm curious how extensive your rails app is to be able to have 3 mongrels on a 256M slice. With my app, I can barely get 1 mongrel running, and even then I'm still swapping. I do have a background rails task, so that counts for another rails instance. Still, 3 is out of the question for a 256M slice. On my 512M slice, I can barely get 2 mongrels going.
I posted my disappointment in the forums since I came from a 32 bit distro where the exact same application could have 7-8 mongrels going in 1 Gig with plenty of room to spare (~55M per mongrel).
I wonder how mod_rails would help me.
PickledOnion commented Tue May 06 09:24:58 UTC 2008 ago:
Hi Dave,
I don't know what is going on with your Slice or what may be misconfigured (it's all I can think of at the moment) but something is very wrong with your setup.
On a 512 Slice you should be able to get 5 or 6 mongrels running with no issues whatsoever as far as memory is concerned.
It is well beyond the comments to be able to diagnose what is wrong but if you are running 1 mongrel and it is swapping then it is possibly the application code?
Just a guess on my part but I have never seen the figures you mention (1 mongrel and swapping, etc) before.
PickledOnion
Ohamana commented Wed May 07 10:03:05 UTC 2008 ago:
Hi, thanks for the nice article.
Anyway, I'm experiencing a strange problem.
I configured apache2 and passenger on my ubuntu 7.10 box with no difficulties, but when I access to my rails app(just for testing) it gives an error message saying that I don't have permission to my public directory.
So I even changed whole directories' permissions to 777, and set it's owner to 'www-data' but that doesn't helped.
What can be the problem? I just modified 'apache2.conf' and 'sites-available/default' files. Apache is running well.
Cody commented Sun May 18 17:21:20 UTC 2008 ago:
I would highly recommend updating the article and including the bit about RailsMaxPoolSize. Adding something like:
RailsMaxPoolSize 2To the vhost is very important on a 256MB slice. As an example, for a slice serving subversion repositories and running Warehouse (rails app) as the front end, I'm seeing up to 230MB of RAM being used, that's with only 2 Passenger processes. This includes of course MySQL, 8 Apache processes, and 2 Passenger processes. So to leave the RailsMaxPoolSize at the default (something like 20 processes could be spawned) would cause some trouble for a lot of folks. I'd recommend RailsMaxPoolSize of 2, maybe 3 depending on the rails app in question and the amount of Apache processes that can be spawned (make sure MaxClients isn't set to crazy number!), the database server in use, etc.
Ralph commented Tue May 20 20:04:50 UTC 2008 ago:
I've found both the article and the comments quite helpful. Thanks.
Whenever you can get to it, I suggest updating the "Configuring Capistrano" articles with information about deploying with Passenger instead of Mongrel.
dynamethod commented Mon Jun 09 05:00:37 UTC 2008 ago:
Im getting this quiet a bit with RoR and Mysql + Apache2.2
once i click on "About you application's enviroment"
i get this:
Routing Error
No route matches "/rails/info/properties" with {:method=>:get}
mez commented Wed Jun 11 06:21:10 UTC 2008 ago:
I am having issues loading multi rails app with mod_rails. Also The only way I can get one app running is if I add the VirtualHost to the /etc/apache2/http.conf. If I try running what you have above it simply does not work. Any help would be great.
cheers
PickledOnion commented Wed Jun 11 09:37:08 UTC 2008 ago:
Hi mez,
One simple question: Are you using Ubuntu Hardy?
I suspect you are not as you are using http.conf which Ubuntu Hardy does not use.
If you are not using Hardy then it won't work - as the title suggests this article is for Ubuntu Hardy only.
PickledOnion
Rick Sandhu commented Sat Jun 14 21:58:43 UTC 2008 ago:
I am getting the same error as 'mez' and it is quite annoying:
Message:
Routing Error
No route matches "/rails/info/properties" with {:method=>:get}
System Configuration:
Ubuntu LTS 8.04 Apache 2.2 Ruby 1.8.6 Rails 2.1.0 Passenger 1.0.5
Rob Clarke commented Sun Jun 22 11:01:18 UTC 2008 ago:
I have just tested on my local machine and "About your application's environment" (and /rails/info/properties) don't work in production. So it is normal that it doesn't work because passenger uses the production environment.
Fadhli commented Mon Jun 23 00:51:08 UTC 2008 ago:
Any articles on using mod_rails and capistrano?
Robert Felty commented Wed Jun 25 13:31:17 UTC 2008 ago:
@Fadhli - This was a pretty good article on mod_rails and capistrano: http://jimneath.org/2008/05/10/using-capistrano-with-passenger-mod_rails/
Andy commented Sun Jul 06 03:45:56 UTC 2008 ago:
Hello. I am deploying from github. I set up modrails and the setup looks good, but Capistrano keeps trying to run script/spin and fails because I haven't created this. I did this one other time using Apache+Mongrels from another slicehost article, however with modrails, I would not expect to have to create a script/spin. Am I incorrect?
Rails 2.1.01Capistrano v2.4.3