After a --long-- recess I am once again in a position to share what I have recently learned concerning Ruby on Rails and everything tied to it.
Today's post will cover server administration, particularly the setup of a new webserver that will handle all of your ruby on rails and php projects. Now, this server is just what I needed for my testing environment - and should work great for the few sites I host!
This will be a two part post, but I plan to release them both within the week. So let us begin by mapping out all the major components of our new server:
- Ubuntu 6.10 (Edgy - Debian based!)
- Ruby 1.8.4 (the bread)
- Rails 1.1.6 (and butter)
- MySQL 5 (my favorite DB - close second, DB2)
- Lighttpd (fastcgi webserver)
- PHP 5 (fast-cgi enabled)
- CVS (source code repository)
- Exim (for mail)
- Vsftp (paranoid and secure FTP server)
Well, this will be a well rounded server that will give you the option to use either the desktop environment, or good ole command line (my preference, in fact I'll show you how to disable the desktop if you no longer need it at the end). So, lets get started:
First go to:
I am going to assume that you have a fair level of comfort in installing an OS, especially one as easy as Ubuntu. So, I will skip all the details and just assume that you have successfully setup Ubuntu on your system. Besides, there are a ton of easy guides to the initial install of Ubuntu. So I would prefer to spend my time explaining all the changes we will make to our future Ruby on Rails development server.
So, now that you have Ubuntu installed we are ready to install lighttpd, ruby, rails, mysql php and more. So lets start by making it possible for us to get all these packages. Open a konsole window (Applications -> System Tools -> Konsole) and enter the following command:
sudo nano /etc/apt/sources.list
Uncomment the following lines:
deb http://us.archive.ubuntu.com/ubuntu/ edgy universe
deb-src http://us.archive.ubuntu.com/ubuntu/ edgy universe
deb http://security.ubuntu.com/ubuntu edgy-security universe
deb-src http://security.ubuntu.com/ubuntu edgy-security universe
Hit Ctrl+X to save -- when prompted, enter Y to save the changes to the file. Now we are ready to update apt-get's list of available packages so we can install what we need. Then, after we update, its time to start installing a few packages. Of course you can always use the apt-get -s [programs-to-install] syntax (adding the -s option) to any of the below commands so you can see what will be installed first.
sudo apt-get update
sudo apt-get install ruby ri rdoc libmysql-ruby mysql-server
Now that ruby is installed (and mysql) we should get rubygems so we can install rails. To get the release that is current at the time I wrote this, do the following commands:
sudo wget http://rubyforge.org/frs/download.php/11289/rubygems-0.9.0.tgz
tar -xvzf rubygems-0.9.0.tgz
cd rubygems-0.9.0
sudo ruby setup.rb
After you finish the setup, feel free to remove the .tgz and rubygems folders from your desktop. Now its time to install rails - that beautiful one liner coming at ya:
sudo gem install rails --include-dependencies
Rubygems does the magic, of course it prompts you on several dependent packages - all of which you should answer "Y" to. So, now your Ubuntu distrobution has rails, and is ruby enabled. Go ahead, run that "ruby -v" and "rails -v" commands on the Konsole - it'll make you smile =)
Well, I know this is a bit short, but I'll finish this out before Christmas with all the remaining packages. Most importantly I will detail all the changes to config files and settings you will need to make. Once we are complete, we will have a fully functioning server to develop (with source code control), test, and host your ruby on rails and php sites. Stay tuned!

Bud said:
FYI, I've found that Ubuntu/Debian does not like gems! apt-get should be used instead to get the appropriate package (eg. sudo apt-get install rails irb). So far, I've always been able to find a package for anything gems can get. See: http://pkg-ruby-extras.alioth.debian.org/rubygems.html
2006-12-24 10:27:55 UTCCharles said:
Interesting read, thanks for pointing that out Bud. I did not have any problems installing using rubygems, but will use this as a reminder in case I do.
I can agree with many of their arguments (besides, i love apt-get ... the main reason I am a debian fan)
2006-12-24 11:28:13 UTCCharles said:
As a personal note - this is my first experience with Ubuntu, and I have to say - it certainly lives up to all the hype. I couldn't be happier in the way it handles! Anyone looking for a great distro that is easy to use (and has a great up to date packaging system) should definitely get Ubuntu!
My previous and current running linux experience is with (no particular order)
[ Debian - my first favorite distro ]
2006-12-24 14:13:11 UTC[ College Linux ]
[ Red Hat 9 ]
[ Red Hat Enterprise 4 ]
[ Gentoo - very fun to setup, alot of configs ]
[ Suse ]
[ Knoppix, Lindows, Insert, GeexBox, various other live cds ]
Jonathan said:
Hi,
thanks for this tutorial, it's great that people like you write this type of stuff. I am fairly new to ruby and completely new to linux (have developed a ruby app recently on windows) and have a few questions.
- Is it easy to replace mysql with Postgresql in your tutorial?
- When ftping the app to the folder mydomain.com, should the app be in the folder or should the app be called mydomain.com ? (is it gonna look like forthecode.com/myrubyapp/)
- I got an error the first time I restarted the lighttpd, saying that it could not find dispatch.fcgi, I change the conf file to point to mydomain.com/myrailapp/public/dispatch.fcgi instead of mydomain.com/public/dispatch.fcgi. Is that the right thing to do or did I get it wrong ?
- When restarting lighttpd after ftping I get a permission denied on the access.log file. Do you know what this could be? I do not have rights to change the permissions on the access.log file.
I'd greatly appreciate if you could help me with some of the questions I have here ;) Thanks in advance
2007-03-08 17:24:21 UTCCharles said:
Hi Johnathan,
Sure, you could replace MySQL with Postgresql... just do an apt-get for Postgresql instead (I cannot give you exact command - because im uncertain of it-- im a MySQL fan! personal preference).
In my setup the following directory (/var/www/forthecode.com/) holds all of these folders- which should be quite familiar to you:
[app components config db doc lib log public Rakefile script test tmp vendor ]
In my example - Lighttpd runs as the user www-data (see the config file in part 2!)
## change uid to (default: don't care)
server.username = "www-data"
## change uid to (default: don't care)
server.groupname = "www-data"
And since I am ftping as www-data then all my files are accessible by Lighttpd. So, this prevents any errors. Of course this is not meant to be a shared hosting environment server (so dont try to set this up with a bunch of other hosting accounts because any account could change the files in the other www-data directories.)
I hope I covered your questions with this brief reply!
2007-03-19 01:01:44 UTCAnonymous said:
Hi Charles,
2007-03-18 19:04:38 UTCthanks for the reply. Yes your answers covered it. I've managed to run my app now with my server and all installed. I've made a much simpler config file to start with as I have only one app on one domain to run. I hope you ll be able to see my site very soon. It will be on www.kaskado.com (right now password protected site). It's a video sharing site built with ruby and adding also mobile functionalities...
/J
Charles said:
Sounds great.
Looking forward to checking it out!
2007-03-18 21:15:36 UTC