HOWTO: Install Ruby on Rails on Fedora Core (Mongrel + Lighttpd)
The goal of this article is to create a "Production-Quality" Rails Server. Thus, the best possible technologies (strictly my opinion) have been selected at the time of this writing to achieve this goal.
Unlike other developers, I prefer to install my Rails Applications under Web Subdirectories, such as http://www.not404.com/MyRailsApp, instead of running it as a Root Application of a Web Root, such as http://MyRailsApp.not404.com/. These instructions are geared for how I lay things out, but will let you know what to adjust in order to run your Rails Apps as traditional Web-Root Applications.
You may also notice that these instructions are SQLite3-oriented. This is intentional. IMHO, it's better to use the simplest-case database to prove that everything else is properly stitched together. Then, once you're satisfied that everything is properly locked down and performance-tuned, you can focus your attention on tying your Rails Application to a real database.
- Fedora Core (6 or later)
- Ruby on Rails
- Mongrel Ruby Application Server
- Lighttpd Web Server
- Various Plumbing and Configuration "Best Practices" to stitch it all together. :-)
Related Articles:
Update For Fedora 8
The Ruby on Rails support in Fedora 8 is superb, and there are RPMs that handle everything about this configuration. Note that the most common Ruby Gems are available as rubygem-* in the Yum Repositories. (You can do a yum search rubygem for a complete list of Fedora-Supplied Ruby Gems).
Thus, through Fedora 8's Yum support, you can install Rails, Lighttpd, and Mongrel in one command:
yum install ruby ruby-devel rubygem-rails rubygem-mongrel lighttpd lighttpd-fastcgi
The following instructions are specific to Fedora Core 6. If you're using Fedora 8, you can skim through most of the Installation Procedures, but pay attention to the Configuration Procedures -- particularly for the Lighttpd Proxy and the Mongrel Cluster as a Startup Service.
Fedora Core 6: The Base Server
- Install Fedora Core 6. Enable the "Development Tools" group in the initial setup screens.
- do a yum -y update to get the latest update patches
- Optionally, do a visudo to configure "sudo" access.
If you missed the "Development Tools" checkbox, do a yum -y groupinstall "Development Tools" to install it now. You'll need the GCC compiler to build some Ruby Gems, it makes sense to have it ready here. After everything's configured, you may decide to do a yum -y groupremove "Development Tools" to remove the C compiler and other tools from your production box.
Ruby On Rails
- yum -y install ruby ruby-devel ruby-irb ruby-libs ruby-rdoc ruby-ri rubygems
- yum -y install ruby-sqlite3
- Now, we can use Gem to get the latest Rails Framework:
- sudo gem install rails --include-dependencies
Optional (But Recommended) Yum Packages
- ruby-sqlite3
- ruby-mysql
- ruby-postgres
- ruby-clearsilver
- ruby-racc
- subversion-ruby
- ruby-docs
Mongrel Ruby Application Server
- sudo gem install gem_plugin daemons capistrano --include-dependencies
- sudo gem install mongrel mongrel_cluster railsmachine --include-dependencies
- sudo /usr/sbin/adduser -r mongrel (This creates a mongrel user, as suggested in Bryan Thompson's Blog).
As I've mentioned before, I prefer to install my Rails Applications under Web Subdirectories, such as http://www.not404.com/MyRailsApp. Most of the other deployment tutorials and strategies advocate installing the Rails Application under the Web Root directory: http://MyRailsApp.not404.com/.
To correctly handle Rails Applications running under Web Subdirectories , we need to use Mongrel's --prefix support, recently added in Mongrel Cluster 0.2.1. At this writing though, Mongrel Cluster 0.2.1 is still a pre-release version, so it needs to be installed from their "trunk" repository, instead of from the standard Gem Repositories.
To get the Pre-Release version of Mongrel Cluster to let us run Rails Applications under Web Subdirectories, run this command:
- sudo gem install mongrel_cluster --source http://railsmachine.rubyforge.org/releases/
- sudo gem cleanup
Test Mongrel and Rails As a Non-Root User
- cd ~
- rails testapp
- cd testapp
- mongrel_rails start
Launch firefox, and go to http://localhost:3000 -- you should get the "Welcome Aboard" web page. You can now stop Mongrel, so we can configure it as a Service.
Configure Mongrel for Production
Because everyone lays out their Production Directories differently, I'll just call the Production Root Directory $PRODUCTION in this article, and I'll assume that Application Instances are in subdirectories, which I'll call $APP_ROOT. For my Production Servers, I like to lay things out this way -- it makes things easier to create master startup scripts that can iterate over all $APP_ROOT instances in $PRODUCTION. I also configure $APP_PORT to a unique service port for each instance on my Production Server.
Please substitute my variables with your own directory structures as appropriate.
If you're following along with my layout, now's a good time to copy ~/testapp to your Production Area:
- sudo mv ~/testapp /$PRODUCTION
- sudo chown -R mongrel:mongrel /$PRODUCTION/testapp
Install Mongrel_Cluster a Startup Service
- sudo mkdir /etc/mongrel_cluster
- find /usr/lib/ruby -type f -name "mongrel_cluster" -exec sudo cp -ap {} /etc/init.d/ \;
- sudo chmod +x /etc/init.d/mongrel_cluster
- sudo /sbin/chkconfig --level 345 mongrel_cluster on
Install Mongrel_Cluster Controller Tool
(I've not found a use for this, but since others think it's important enough to document, I've put it in . . .)
- find /usr/lib/ruby -type f -name "mongrel_cluster_ctl" -exec sudo ln -s {} /usr/bin; \;
Configure Mongrel_Cluster For Each Application Instance
(NOTE: The following hunk is a pseudo-script, just to give you an idea of what I do on my machines. It's not a complete bash script)
- export APP_PORT=8000 # Change this as needed
- export APP_NODES=3 # Change this as needed
- cd $PRODUCTION/$APP_ROOT
- sudo mongrel_rails cluster::configure -e production -c $PRODUCTION/$APP_ROOT -p $APP_PORT -N $APP_NODES -a 127.0.0.1 --user mongrel --group mongrel --prefix /$APP_ROOT
- sudo ln -s $PRODUCTION/$APP_ROOT/config/mongrel_cluster.yml /etc/mongrel_cluster/$APP_ROOT.yml
Note that my instructions above include the new --prefix $APP_ROOT command, which allows Mongrel Applications to properly "ignore" the prefix. Prior to this Mongrel Enhancement, we needed to configure Apache or Lighttpd to strip out this prefix.
If you're running your Rails Apps as the web server root application, remove the --prefix /$APP_ROOT additions.
Lighttpd Web Server
At this point, you now have your Mongrel-Rails Applications properly configured to run as Startup Services. (They'll automatically startup when your machine reboots). Now it's time to stitch together the Lighttpd Web Server as our front-end.
Install Lighttpd
- sudo yum -y install lighttpd
- sudo /sbin/chkconfig --level 345 lighttpd on
Configure Lighttpd For Mongrel
- sudo nano /etc/lighttpd/lighttpd.conf
Uncomment the mod_proxy module, as we'll need that to dispatch requests to our Mongrel Serves.
Additional (Recommended) Modules For Lighttpd
Out of the Box, Fedora's Lighttpd configuration is rather light. You may want to uncomment these additional modules to get more functionality.
- mod_rewrite
- mod_redirect
- mod_access
- mod_accesslog
- mod_compress
Configure A Mongrel-Cluster In Lighttpd
Add a hunk of code similar to the following to the tail end of /etc/lighttpd/lighttpd.conf:
proxy.balance = "fair"
proxy.server = ( "/testapp" =>
( ( "host" => "127.0.0.1", "port" => 8001 ),
( "host" => "127.0.0.1", "port" => 8002 ),
( "host" => "127.0.0.1", "port" => 8003 ) ) )
You will need to change the /testapp prefix to the name of your Rails Application. Remember that $APP_ROOT variable that we passed to Mongrel as --prefix? Yes, the value you input here must match that --prefix value. Obviously, you will also need to change the Mongrel Server-Ports to match your $APP_PORT, up to $APP_NODES instances for this server pool.
If you are running your apps in the root-directory, change "/testapp" to "/"
That should be it! Now you can fire up the whole shebang and cross your fingers:
- sudo service mongrel_cluster start
- sudo service lighttpd start
Various Plumbing and Best-Practices
(more to come)
Additional References
This article couldn't have been put together without referring to older documentation:
- Official Mongrel FAQ
- Official Mongrel-Lighttpd HOWTO
- Apache 2.2 + Mongrel on Fedora Core 5 installation guide
- Five-Minute Rails Application Deployment
- Time For A Grown-Up Server: Rails, Mongrel, Apache, Capistrano and You
- Installing Ruby on Rails on Fedora Core 5
- Installing Ruby on Rails with Lighttpd and MySQL on Fedora Core 4
- Rails on Fedora
- Mongrel Cluster 0.2.1 pre-release Announcement
Contacting The Author
If you need additional Ruby on Fedora support, or are looking to hire an experienced Ruby On Rails Developer, feel free to contact me (Laurence Lee) as username lalee_net, at yahoo.com.
User Comments and Feedback
Comment by Aaron on Thu Mar 29 16:25:33 2007
I actually wrote the BryanThompsons blog article, you have a great howto here, good work!
Comment by anonymous on Thu May 3 12:04:27 2007
Thanks for the HOWTO... worked like a charm for my very first Rails installation :-)
Comment by Sam Pierson on Thu Jun 14 14:46:34 2007
In section: Install Mongrel_Cluster a Startup Service I think you mean:
- sudo mkdir /etc/init.d/mongrel_cluster
Comment by lalee on Wed Jun 20 17:13:44 2007
Sam,
It's a matter of personal preference, I suppose. I create /etc/mongrel_cluster as a directory that stores all of the Mongrel Configuration Files deployed across all applications. For me, it makes more logical sense to keep it as a subdirectory of /etc (the system-wide configuration directory), rather than in /etc/init.d (the system-wide configuration-scripts repository).
As far as I can tell in Fedora's layout, most of the services have configuration directories directly under /etc, too, so at least I'm being consistent with what's already in place. :-)
Comment by anonymous on Sat Oct 27 22:59:10 2007
The biggest problem I have with FC6 is that rails for the x64 version is still stuck at 1.8.5. This is inadequate if you use certain methods ( Time.to_datetime for example). I'm trying to manually build Ruby 1.8.6 and rubygems, but the rubygems installer complains about missing zlib.. any thoughts?
Comment by michael on Sat Oct 27 23:00:10 2007
previous should have read "ruby for the x64 version".
Comment by lalee on Sun Oct 28 01:37:06 2007
You might want to upgrade to Fedora7, or wait to grab Fedora8 since it's scheduled for release on November 8. Fedora7-x64 has Ruby 1.8.6 available.
Comment by Lou Arnold on Sun Nov 18 09:19:21 2007
This was quite good, but for us Ruby first timers, it might be nice to give somewhat more: 1) Folders to change to before executing commands. 2) For optional packages/utilities - what are they/why or when would you need them. 3) Some servers - Mongrel in particular - would go on a second server computer. It would be nice to have some sense of how those are configured to work with Ruby and Rails on a development computer.
Comment by lalee on Mon Nov 19 13:19:11 2007
Thanks for the feedback, Lou. I have been considering an overhaul of this article for Fedora8 for quite some time, and those suggestions will help take it into a new direction.
Best Regards,
Laurence Lee















not 404 anymore
I just went through a big server move and accidentally forgot about the subdomain i had been using for that blog. Anyway, I just moved it over and fixed the dns, so my referenced post will work again. I plan on updating it with new instructions, but I haven't had time.
Excellent (I think best) article on Installing Rails on Fedora
Hi! Thanks for the Excellent article. I think its the best artcle available on net on the topic: "installing rails on Fedora". Before it, I was struggling to install Rails on Fedora 8. But it made my life easy. Thanks a lot. I hope, Rails will make this article their official installation manual for Fedora (Specially Fedora 8)