January 2007
Edgy on Rails? Get compiling!
Love Ubuntu and want to run a Rails server on Edgy Eft (Ubuntu 6.10)? Roll-up your sleeves for some "compiling from source" fun.
Please note that Ubuntu Fiesty Fawn has been released. It comes with Apache 2.2. If you can, avoid all this compiling and just sudo apt-get dist-upgrade!
Rails development on Ubuntu is a breeze, you can apt-get all the stuff you need. From Ruby 1.8.4 and MySQL driver to ImageMagick, the official repositories have got you covered. Deployment is another story. The bad news is that stuff that comes with Edgy just doesn't work, the good news, compiling stuff in Ubuntu, and Debian in general, is really easy.
Where's what we need to compile:
Apache 2.2
Because you can't do serious Rails deployment without a Mongrel cluster, and Mongrel needs a Load Balancing Proxy so that browsers can connect to the standard port 80. Ubuntu comes with Apache 2.0, which is no good because mod_proxy_balancer was not introduced until Apache 2.2. We need to grab Apache 2.2.x from the source and compile it ourselves.
Note: You _can_ use lighttpd but I wouldn't use it's mod_proxy plug-in. Why? Because it's load balancing bit is buggy and Zed says so. If you must use lighty, use Pound to do the load balancing (see below).
No point re-inventing the wheel, the good folks at Starman will show you how to build Apache 2.2. Don't have time to read? Simply get the latest Unix source from the Apache download site. Get some stuff from Ubuntu universe:
-
sudo apt-get install build-essential libpcre3-dev libssl-dev libdb4.3-dev libneon25-dev
Remove existing Apache package, untar the Apache source and run:
-
./configure --enable-deflate --enable-proxy --enable-proxy-html --enable-proxy-balancer --enable-rewrite --enable-cache --enable-mem-cache --enable-ssl --enable-headers --enable-logio
Followed by
-
make ; sudo make install
This will install Apache 2.2.3 in /usr/local, which is where I like it because it doesn't get confused with Ubuntu maintained stuff. You will have to point your /etc/init.d/apache to the new apachectl.
Pound
Pound is a decent standalone load balancer. You can learn more about using Pound with Mongrel here. One advantage here is that you can use lighttpd as a web server + proxy and let Pound do the balancing. It is quite configurable and comes standard with Ubuntu. Well, sort of. The Ubuntu Edgy package doesn't work very well. In my case, it kept crashing without any warnings. If you do want Pound, you will have to compile from source. Rob Orsini explains how to setup lighty, Pound and Mongrel here. Long story short, download Pound and untar (tar xfz) it.
-
sudo apt-get install libpcre3 libpcre3-dev
-
./configure; make ; sudo make install
Memcached
Memcached is an in-memory cache that can help take the load off your database. I was attempting to use memcache as my Rails session store but the standard Edgy package refused to work for me. Rails would complain that my session was expiring within a few navigations. This would only occur under a Mongrel cluster; a single Mongrel or Webrick would have no problems. Strange.
So I got the latest memcached source and repeated the compile drill:
-
sudo apt-get install libevent-dev
-
./configure; make; sudo make install
This fixed the problem but for some reason memcached would occasionally halt for several seconds, making my site slower rather than faster. I finally gave up on memcached and decided to settle for SqlSessionStore, which works like a champ! If any of you have insight or experience with this issue, please let me know.
All this compiling, albeit easy, should not be needed. The biggest downside of compiling is that you don't get to apt-get upgrade things. You could be missing out on a critical patch. If only the Ubuntu package maintainers would stay current, or someone (like you and me) would just take some time to build DEBs and publish a "Ubuntu on Rails" repository.
SD Times - Rails for Tactical Business Applications
SD Times recently published my article on Tactical Business Applications with Ruby on Rails. It discusses the advantages of using Rails to fulfill enterprise business needs.
Get the full article here: SD Times - Rails for Tactical Business Applications