There are a lot of things to really love about Rails apps. One of them is not deployment. Rails boffins, regardless of what they say, do look with longing envy over at those php kids with their simple copy of files up to a server and having it run on apache.
Admittedly, I’d rather deploy via capistrano anyway (cause even php boffins should be doing it that way) since it is fabulous and does deployment like it should be done, but there is something to be said for the wonderful mod_php under apache. Configuring proxying and mongrels under either apache or nginx is simply not fun. It feels like work.
This blog, and other subdomains on wakatara were first running on nginx and mongrels for the longest time. I’d since moved back over to apache since I needed the domain to do a few other things that nginx would have required too much futzing over, but with people like 37Signals moving over to passenger (or mod_rails as it’s sometimes known) it seemed like a good move to simplify the overall fussiness of running too many mongrels behind apache and simplifying my maintenance, deploy and monitoring complexity.
Anyhow, moved things over in roughly half an hour of work (and that’s erring on the side of long, it was very fast to make the move) and the server now seems to have a lot more free memory overall, as well as definitely being way more responsive. Where I had roughly 10 MB free before, killing off 2 mongrel clusters of two mongrels each and a single mongrel for a wiki has freed up a whopping 175 MB (!) when the site is being hit (300 MB when it’s not that active !). And that’s ginormous memory savings. We’ll see just how stable that is over time and load though.
I also have to admit to loving how to bounce the servers as well as it no longer requires clustering commands and the like.
Will follow up with some “living with” posts later on over the end of year break I’m taking from work.
In case you wanted to repeat the same, here’s how to install Phusion Passenger (mod_rails) on Ubuntu 8.04 server.
Passenger compiles a module for apache2, so requires Apache2’s development headers. Ubuntu being minimal doesn’t put this in up front, so install the following (the passenger install would tell you to anyhow) :
1 sudo apt-get install apache2-prefork-dev
Once that’s all done, then it’s time to install Passenger itself. Couldn’t be easier if you’ve already got your Rails and gem stacks installed
1 sudo gem install passenger
yep, that easy… then you need to compile the apache2 module. Quite simple as well :
1 sudo passenger-install-apache2-module
The command id nice and walks through the compile and lets you know what you need to do.
After it’s done, it tells you to copy the following lines into your ``/etc/apache2/apache2.conf`
1 2 3 LoadModule passenger_module /usr/lib/ruby/gems/1.8/gems/passenger-2.0.3/ext/apache2/mod_passenger.so PassengerRoot /usr/lib/ruby/gems/1.8/gems/passenger-2.0.3 PassengerRuby /usr/bin/ruby1.8
If you haven’t got it already going, make sure you’ve got mod-rewrite enabled on apache2. You can check your /etc/apache2/mods-enabled directory to see if it’s active or just run the following :
1 sudo a2emod rewrite
Now you’re basically good to go. Create a nice vhost file like subdomain.domain.com in /etc/apache2/sites-available with something like the following :
1 2 ServerName subdomain.domain.com DocumentRoot /path/to/subdomain.domain.com/public/
Note, that if you’re like me and have deploying via capistrano, the DocumentRoot will be something like
/path/to/subdomain.domain.com/*current*/public . Quite important, as the next step is to change your cap deploy recipes to make your life easier.
That’s about it actually (I had to shut down some mongrels and comment out some stuff in my vhost files from the old apache to mongrel cluster setup but basically if you’re starting from scratch, right now you just have to upload your files or cap deploy them to the same location).
Then to get it all going just :
1 sudo /etc/init.d/apache2 restart
And you should have everything running on passenger instead of mongrels.dev rails tools