Using Ruby On Rails With Apache2 On Debian Etch

Want to support HowtoForge? Become a subscriber!
 
Submitted by falko (Contact Author) (Forums) on Sun, 2007-05-27 15:59. :: Debian | Apache

Using Ruby On Rails With Apache2 On Debian Etch

Version 1.0
Author: Falko Timme <ft [at] falkotimme [dot] com>
Last edited 05/19/2007

This article shows how you can install Ruby on Rails (RoR) and integrate it in Apache2 on a Debian Etch system (including a short section at the end showing how to use RoR in a web site created with ISPConfig). Ruby on Rails is a web application framework which is rapidly gaining popularity among web programmers. It aims to increase the speed and ease with which database-driven web sites can be created and offers skeleton code frameworks (scaffolding) from the outset. Applications using the RoR framework are developed using the Model-View-Controller design pattern.

This document comes without warranty of any kind! I want to say that this is not the only way of setting up such a system. There are many ways of achieving this goal but this is the way I take. I do not issue any guarantee that this will work for you!

 

1 Preliminary Note

I will use the hostname testapplication.example.com in this tutorial for the virtual host running Ruby on Rails.

 

2 Installing Ruby And Rails

In order to install Ruby and Ruby on Rails, we simply run

apt-get install ruby libzlib-ruby rdoc irb rubygems rails eruby

 

3 Installing Apache2 And mod-fcgid

Ruby on Rails can be integrated in Apache2 using mod-fcgid. Therefore we install the following packages:

apt-get install apache2 libapache2-mod-fcgid libfcgi-ruby1.8

Afterwards, we enable a few Apache modules:

a2enmod ssl
a2enmod rewrite
a2enmod suexec
a2enmod include

and reload Apache:

/etc/init.d/apache2 force-reload

 

4 Installing MySQL And The Ruby MySQL Bindings

Most probably you or your users will like to create database-driven Ruby on Rails applications, therefore we install the MySQL server and the Ruby MySQL bindings now:

apt-get install libmysql-ruby mysql-server

You should set a root password for MySQL now:

mysqladmin -u root password yourrootsqlpassword

If MySQL is listening not only on 127.0.0.1, but on other addresses as well (e.g. server1.example.com), you should set a root password for these addresses as well:

mysqladmin -h server1.example.com -u root password yourrootsqlpassword

 

5 Creating Our Ruby On Rails Environment

We can now create a directory in which we want to develop our future RoR applications. I'd like to develop them in /var/rails, so I create that directory now:

mkdir /var/rails

Apache2 should have read/write access to that directory, so we make the Apache user (www-data on Debian) and Apache group (again www-data) the owner and group of that directory:

chown -R www-data:www-data /var/rails

Now we can create our first RoR application which we will call testapplication. We will create testapplication under the user www-data so that Apache has read/write access to it:

cd /var/rails
su -m www-data

Now that we're logged in as www-data, we run

rails testapplication

This will create a directory called testapplication within /var/rails that contains all directories and files we need to develop our RoR application.

Next, we type in

exit

to become the root user again.


Please do not use the comment function to ask for help! If you need help, please use our forum.
Comments will be published after administrator approval.
Submitted by mc0e (not registered) on Sun, 2012-08-12 09:41.

This recipe looks like it'll create a rails app directory where
all the code and templates are owned by the www-data user, which is poor
practice from a security standpoint.  gazmcghee raises concerns about the ruby version.  However, the link they point to is now lacking content.  In general, I've been concerned by the lack of secure download sources (ie cryptographically signed) for ruby other than those that come from the operating system vendors.  There's a lot of situations where you might ignore the issue, but I would have thought the ruby community would have matured enough by now to provide such things for those who do need it.

Submitted by Douglas (not registered) on Sat, 2012-05-05 16:08.

Pretty good for the apache2 part even though this is old. I 'm running

debian squeeze now. All except for the rails part. I use rvm and do not install any ruby as a root user. An article on how to use this with rvm would be nice. Keep in mind that there is also passenger and passenger gem now.

Thanks! Good job.

OG1

Submitted by sadf3f4fw (registered user) on Tue, 2008-01-08 11:41.

see rails wiki post: http://wiki.rubyonrails.org/rails/pages/RailsOnDebian

"Note:
Do not install rails using apt-get! The debian repository includes a very old and broken version."

Submitted by gazmcghee (registered user) on Tue, 2007-11-20 04:45.

This guy seems to be a sys admin, not a Ruby developer. Rubyists almost without exception use mongrel, not fcgi, and this tutorial results in an old version of Ruby (via apt-get). To get Ruby 1.8.6 on Debian you have to compile it - see http://www.urbanpuddle.com/articles/2007/08/17/mongrel-cluster-1-0-2-and-ruby-1-8-5

Submitted by gerard (not registered) on Wed, 2009-09-23 01:58.
The point of the article was to show how to get RoR on apache2, not on mongrel, which is an entirely different HTTP server.
Submitted by evden eve nakliyat (not registered) on Wed, 2010-01-27 03:53.
Good work! Your post/article is an excellent example of why I keep comming back to read your excellent quality content that is forever updated. Thank you!