Setting up Ruby and Rails

Installing required packages

First you'll have to get the required ruby packages:

          apt-get install libruby libruby1.8 ruby ruby1.8 libzlib-ruby1.8 libyaml-ruby1.8 rdoc1.8 libiconv-ruby1.8 irb1.8 libreadline-ruby1.8 libcurses-ruby1.8 libbigdecimal-ruby1.8 libdrb-ruby1.8 liberb-ruby1.8


Now that everything is in place, get RubyGems. Either compile it from source or install Debian packages by adding

          deb ./
deb-src ./


to your /etc/apt/sources.list and running

          apt-get install libgems-ruby libgems-ruby1.8


Now you should have met all requirements to install rails with gem. To do this, run:

          gem install rails


Installation script will prompt you about installing dependencies (rake, activerecord, actionpack, actionmailer) - press Y to all questions.

Creating a new Rails application

Go to the directory of your choice and run this command:

          rails your_application


Chances are, if you did everything as written above, it will print a lot of commands and exit without errors, leaving you with the following folder hierarchy:

Congratulations, you've just created a framework for your first Ruby On Rails app! You can now start a WEBrick servlet by running

          cd your_application
ruby script/server


which will fire up a webserver on your port 3000 (open your browser and point to or proceed to set up Apache for running your Rails application.

Modifying Apache config file

Debian has a pretty usable Apache configuration by default so basic setup won't be covered in this article but supposing you already have Apache running your webserver on localhost, I'll show you how to setup a VirtualHost for Rails application we have recently created.

We begin by openning Apache's config file (that is /etc/apache/httpd.conf) in your favorite editor (mind you that this file is owned by root so you should either start the editor in root console or by using sudo). Find the VirtualHost section (the last one) and add these lines right there:

          <VirtualHost *:80>
    ServerName some_name
    DocumentRoot /path/to/your_application/public/
    ErrorLog /path/to/your_application/log/apache.log

    <Directory /path/to/your_application/public>
        Options ExecCGI FollowSymLinks
        AddHandler cgi-script .cgi
        AllowOverride all
        Order allow,deny
        Allow from all


Now we have to change the permissions of app's folder to give Apache full access to its contents. Apache process is running as user www-data of group www-data so open a root console and run

          chown -R www-data:www-data /path/to/your_application


And now we can make Apache reload its config file and see the results by running (as root):

          /etc/init.d/apache reload


But first we have to make sure that our VirtualHost is resolved by your browser. If your server is running locally, the easiest way is to open (once again as root) /etc/hosts in your editor and add some_name (replacing it with the name you set in the VirtualHost config above) to the end of line starting with to have something like this:

 localhost some_name


That's it, now you can open your browser and type: http://some_name

Apache FastCGI setup for Ruby

Installing required packages

Now you have to install FastCGI module for your version of Apache and Ruby's FCGI bindings.

For Apache 1.3.x:

          apt-get install libapache-mod-fastcgi
apt-get install libfcgi-ruby1.8


For Apache 2.0.x:

          apt-get install libapache2-mod-fastcgi
apt-get install libfcgi-ruby1.8


Modifying Apache config file

Open /etc/apache/httpd.conf in your favorite editor and add these lines:

          <IfModule mod_fastcgi.c>
    FastCgiIpcDir /tmp/fcgi_ipc/


Open .htaccess file in your application's public/ folder and change the line

          RewriteBase /dispatch.cgi



          RewriteBase /dispatch.fcgi


to let Apache and Rails know that you want to use FastCGI from now on.