July 10th, 2006
There are a couple of previous walkthroughs on getting Rails working on Debian, so this is really just one of many.
My goal was to create a step-by-step minimal setup – mainly the target audience would be people looking to make something useful out of an old box by turning it into a Rails-capable server. This setup includes Debian Sarge (stable packages only) Linux, lighttpd (web server), and mysql (database engine). If you prefer another linux distro, web server, or database engine, this document will probably be a bit unhelpful.
Part 1. DebianIf you don’t already have Debian on a box somewhere, he’s my quick rundown of how to get the bare minimum going (otherwise, skip to Part 2):
- Get a Debian ISO and burn it. I like to use the netinst CD image. It’s about 110MB and just has the most important juice for the base install. You can find this image at any of the Debian mirrors – personally I like to suck bandwidth from our arch-enemies at OSU (towards the bottom of the list, ending in netinst)
- Boot your box to the CD. I’m assuming you don’t mind blowing away anything that was on this box, so keep that in mind when you go through this. Any data previously on this machine will be wiped out.
- Debian install
- It’s safe to take all the defaults for most of the install.
- When you get to the part about partitioning, you can choose the “All files in one partition” option or the “Multiuser Workstation” option. If you take the multiuser, you’ll get a guided-partioning screen. I usually do this and then accept the default changes and move on. If you’re using a hard drive smaller than about 20GB, I’d go with all one partition so you don’t run into disk space problems later.
- When asked, say “yes” to installing grub on the Master Boot Record
- CD ejects, reboot
- After reboot, you get the Debian base config screen. Select your time zone, create the root password and create a new user.
- Next is Apt setup. Apt is the package management system Debian uses. When it asks you where to look for the package archive, choose ftp or http mirror (not CD!). I use FTP, and then I select debian.oregonstate.edu.
- You get a choice of some pre-made package sets to choose from – at this point, since we just want a box for running Rails, let’s choose the last option, “manual package” installation.
- Aptitude, the menu-driven package selector will come on the screen. Just exit it by hitting ‘q’.
- Exim v4 setup pops up – this is the default internal mail system for Debian – since this is not going to be a mail server, just take the defaults (local delivery only) and move on.
- Debian’s base system is installed!
- You should be at a login prompt. Login as root. At this point I always update my system (I’m using a CD that’s a couple months old and there are always new packages to be updated). At the prompt:
If you need to reboot (sometimes you’ll get a kernel upgrade and the message will tell you to reboot ASAP), do so now with:
aptitude update && aptitude upgrade
shutdown -r now
- I always install SSH next so I can do everything else from a remote connection.
(if you don’t know how to answer the three questions it asks you after installing SSH, I recommend “yes” to all three)
aptitude install ssh
- If you’re going to take my advice and do the rest of the setup remotely, you’ll need an SSH client. Linux and OS X have ssh already from a terminal. Windows-users, I’d recommend putty. Remember, when you connect remotely, you have to log in as the user you created at the beginning of the install. You can’t connect directly to the box as root. First, you log in as your regular user, then you use the “su” command to switch to the root user.
Part 2. Package DependenciesNow that Debian is installed and (hopefully) you can SSH into your box, we need to install all the packages that are required for the rails/mysql/lighttpd gang to function. If you haven’t already, login, and then ‘su’. Copy and paste this whole line at once: (note for putty users: when you copy text into the clipboard, you can paste into putty simply by right-clicking anywhere in the putty window)
aptitude install autoconf automake1.9 bzip2 g++ irb libbz2-ruby1.8 libbz2-1.0 libfcgi-dev libfcgi-ruby1.8 libfcgi0 libpcre3-dev libreadline4 libreadline5-dev libruby1.8 libtool make mysql-server-4.1 pkg-config rdoc ruby1.8 ruby1.8-dev ruby ssh subversion zlib1g zlib1g-dev
You should get a prompt letting you know a bunch of dependencies will be installed as well, so just hit ‘Y’ and enter to continue.
At this point we should have all the necessary packages installed. When I did this, I got both automake1.9 and automake1.4 – in order to set up lighttpd, we need to make sure we’re using the later version of automake, so I just uninstalled the older version (since we don’t need it for anything else):
aptitude remove automake1.4
Part 3. MySQL
Not much to do with MySQL, since Debian does most of the work for us. All you need to really do at this point is set your root mysql password (the root user in mysql is not the same as your Debian root user). Replace newpassword with whatever you want:
mysqladmin -u root password newpassword
Part 4. Lighttpd
Ah, lighty. This web server is an extreme pain in the ass to get installed. We could go with apache, since there are already deb packages for it, but to be honest, after the initial installion, the configuration of apache with FastCGI and rails is even more difficult than getting lighty installed.
Note: At this time (April, 2006) there is a deb package for lighty as well, but it is not nearly up to date enough. It will not work with Rails 1.1.0 or higher. This is why we need to compile lighty from source.
If you followed Part 2 carefully and got all those packages installed, you should be ok. If you get any errors, it’s most likely that you missed one of those packages. Gathering that complete list of packages was the hardest part of getting lighty set up for me, so hopefully you should have no trouble.
Now, then. Go find yourself a directory to download sources to (like /home/yourusername or /usr/local/src or something). Do the following:
cd /usr/local/src svn co svn://svn.lighttpd.net/lighttpd/branches/lighttpd-merge-1.4.x/ cd lighttpd-merge-1.4.x ./autogen.sh ./configure make make install ln -s /usr/local/sbin/lighttpd /usr/local/bin/lighttpd
If you got through all that with no errors, lighty should be working. The last line is to create a symbolic link to the shared bin directory so any user on the box can run lighttpd – you need that if you want to run lighttpd as your non-root user during testing and development. You can tell if lighttpd is working by doing:
# lighttpd -v lighttpd-1.4.12 - a light and fast webserver Build-Date: Apr 14 2006 11:50:05
Part 5. RubyGems
Installing RubyGems is pretty straightforward. If ruby is installed and working at this point (we got all the pieces of it in Part 2), it should be a snap.
cd /usr/local/src wget http://rubyforge.org/frs/download.php/5207/rubygems-0.8.11.tgz tar -zxvf rubygems-0.8.11.tgz cd rubygems-0.8.11 ruby setup.rb
Did it work?
# gem -v 0.8.11
Part 6. Rails (finally, sheesh)
From here on out, it’s Easy Street. Install Rails like this:
gem install rails --include-dependencies
RubyGems will install Rails and all his buddies and generate documentation for them – which will take some time on old boxes. Go get some coffee…
When that’s done, you’ll need at least the mysql gem and the fcgi gem (I think – not sure if this is necessary with lighttpd or if it’s only needed for apache – anyone know?):
gem install mysql gem install fcgi
And any other gems are just as easy to install – for example, RedCloth provides access to the textilize helper.
gem install redcloth
That’s it, you should be good to go. When you start up rails apps in development mode by using script/server, it should use lighttpd instead of WEBrick. The first time you start a rails app with lighty, rails will copy the the default conf file to your config directory. Also, don’t forget to configure config/database.yml with the correct mysql user and password. For detailed production setup of lighty and rails, try the Rails wiki.