Ruby on Rails with Apache on Ubuntu 9.10 (Karmic)

Select distribution:
Traducciones al Español
Estamos traduciendo nuestros guías y tutoriales al Español. Es posible que usted esté viendo una traducción generada automáticamente. Estamos trabajando con traductores profesionales para verificar las traducciones de nuestro sitio web. Este proyecto es un trabajo en curso.

This guide has been deprecated and is no longer being maintained.

Ruby on Rails is a popular rapid development web framework that allows web designers and developers to implement dynamic fully featured web applications quickly that is written in the Ruby programming language. Rails enables developers to produce inventive applications on tight time scales. Examples of well known Rails-powered sites include Hulu, GitHub, and the applications provided by 37 Signals, among many others. This guide deploys Rails applications using the Phusion Passenger or mod_rails method. Passenger allows you to embed Rails apps directly in Apache applications without needing to worry about FastCGI or complex web server proxies.

Installing Passenger and Dependencies

Before updating your system and installing the required software, edit the /etc/apt/sources.list file to enable the Ubuntu’s “universe” repository, so that it resembles the following:

File: /etc/apt/sources.list
## main & restricted repositories
deb karmic main restricted
deb-src karmic main restricted

deb karmic-updates main restricted
deb-src karmic-updates main restricted

deb karmic-security main restricted
deb-src karmic-security main restricted

## universe repositories - uncomment to enable
deb karmic universe
deb-src karmic universe

deb karmic-updates universe
deb-src karmic-updates universe

deb karmic-security universe
deb-src karmic-security universe

Issue the following command to reload your system’s package repositories and ensure that all installed programs are up to date:

apt-get update
apt-get upgrade

Install the following command to install a number of required system packages required for using Ruby, building Ruby modules, and running Rails applications:

apt-get install build-essential libapache2-mod-passenger apache2 rubygems ruby1.8-dev libopenssl-ruby

Using the gem package manager for Ruby modules, install the fastthread gem:

gem install fastthread

Finally, install the version of Ruby On Rails that your application requires. Issue one the following commands for the version you need:

gem install rails --version 2.1.2
gem install rails --version 2.2.2
gem install rails --version 2.3.5
gem install rails --version 3.0.4

If you are unsure of the version you require, you can install the default latest version with the following command:

gem install rails

This should install the appropriate versions of all required packages, including ruby, rack, and other dependencies needed for basic Rails development. To install support for the MySQL database system in Rails, issue the following commands:

apt-get install mysql-server libmysqlclient15off libmysqlclient15-dev mysql-client mysql-common
gem install mysql

Additionally, the application you deploy will likely have additional dependencies. Install these dependencies before proceeding.

Configuring Apache to Work with Passenger

If you configured Apache virtual hosting as outlined in the Ubuntu 9.10 (Karmic) Apache guide, the public directory for your domain (e.g. is located in /srv/www/, and your <VirtualHost > configuration block contains a line that reads:

File: Apache Virtual Host Configuration
DocumentRoot /srv/www/

In typical Passenger-based Rails deployments, the application directory would be located in /srv/www/ For example my-app/ would be located at /srv/www/ Issue the following commands to remove the existing public_html/ directory and create a new symbolic link to the application’s public directory:

rmdir /srv/www/
ln -s /srv/www/ /srv/www/

Passenger requires that the log files within your application be world writable (e.g. chmod 666) and will produce an “HTTP 500 Internal Server Error” if the log files are not writable. Issue the following command to change the permissions of the files in the log directory of the “my-app” application:

chmod 666 /srv/www/

Restart Apache once to ensure all settings have been loaded using the following command:

/etc/init.d/apache2 restart

Modify Rails Applications to Work With Passenger

The version of Passenger distributed with Ubuntu 9.10 (Karmic) may have a minor compatibility issue with your Ruby on Rails application. To correct this, change directories to the app/controllers/ folder of your application and issue the following command to create a symbolic link:

ln -s application_controller.rb application.rb

If your application requires additional configuration including database migrations, configurations, or updates, you may wish to perform those operations at this point.

Deploying Multiple Rails Apps

There are a number of strategies for deploying more than one Rails application using Passenger. The most simple approach requires running multiple distinct virtual hosts configured as above to host a single Rails app each. Alternatively you may host multiple Rails apps within a single virtual host. Add RailsBaseURI directives that specify the path to your Rails application within the VirtualHost configuration, as in the following example:

File: Apache Virtual Host Configuration
DocumentRoot /srv/www/
RailsBaseURI /my-app
RailsBaseURI /frogs
RailsBaseURI /simon

These directives configure Passenger to run three Rails apps on the site at the three locations specified. Rather than linking the public/ directory of your Rails app to the public_html/ directory as above, link the public/ directory of the application to a directory within the public_html/ directory. These links would be created in the following manner:

ln -s /srv/www/ /srv/www/
ln -s /srv/www/ /srv/www/
ln -s /srv/www/ /srv/www/

The files for each Rails application are located in a /srv/www/ directory, which is inaccessible to the web server. Congratulations! You have successfully deployed Ruby On Rails applications with the Apache Web server and Passenger.

More Information

You may wish to consult the following resources for additional information on this topic. While these are provided in the hope that they will be useful, please note that we cannot vouch for the accuracy or timeliness of externally hosted materials.

This page was originally published on

Create a Linode account to try this guide with a $100 credit.
This credit will be applied to any valid services used during your first 60 days.

Your Feedback Is Important

Let us know if this guide made it easy to get the answer you needed.

Join the conversation.
Read other comments or post your own below. Comments must be respectful, constructive, and relevant to the topic of the guide. Do not post external links or advertisements. Before posting, consider if your comment would be better addressed by contacting our Support team or asking on our Community Site.