Ruby on Rails
RailsOnSUSE (Version #44)

SUSE 10.0

These are step-by-step instructions for installing Ruby on Rails under SUSE Linux 10.0. A few things to keep in mind before we begin:

  • This guide is only good for a development environment. Many other factors will have to be considered for a production environment, and there are other pages and even an entire book to cover these.
  • I will not show you for the thousandth time how to install MySQL.
  • Of course, there are other ways to set things up, and there are multiple paths to the same setup. Feel free to experiment.
  • We will be using FastCGI under Apache 2.0, and it will be set up to handle Rails applications in subdirectories, instead of virtual hosts. I feel this is more appropriate for development, as you can add applications without reconfiguring Apache.
  • You need to be logged in as root for this procedure to work.

Install the necessary packages

Launch SUSE’s package manager, YaST, either from the GUI or from the command line (yast). Go into Software Management and use the Search function to locate packages called FastCGI and rubygems. If they are listed, skip the next paragraph.

If your current installation sources don’t include the required packages, go back to YaST’s main menu, and go into Installation Source. Disable your current source(s) and add a new source pointing to the OpenSUSE repository. You can find a list of repositories at OpenSUSE or you can Google for one. For example, add the FTP source suse.mirrors.tds.net, directory pub/opensuse/distribution/SL-10.0-OSS/inst-source. Once you’ve added the source, save your changes and go back into Software Management.

Using YaST, install (or keep) at least the following packages:
  • FastCGI
  • FastCGI-devel
  • apache2-mod_fastcgi (and apache2 itself of course)
  • ruby
  • ruby-doc-ri
  • rubygems
  • zlib

If a conflict dialog pops up, just add the required packages. Also make sure ruby-mysql and ruby-fcgi are unchecked, as we will install them using RubyGems.

Install Rails

As in other distributions, use RubyGems to install FastCGI and (optionally) MySQL bindings, as well as (of course) rails and its dependencies:

$ gem install fcgi
$ gem install mysql
$ gem install rails -y

Set up a directory structure

With SUSE, I like to work under the /srv directory, but you may of course adjust with your own paths. As an example, let’s create the following directories:

  • /srv/www/rails — we will put all our Rails applications under this directory.
  • /srv/www/fcgi-log — this will hold the FastCGI crash logs. This is necessary because we’ll be using symbolic links and I’ve found that this makes RoR’s default FastCGI log path invalid.

Also, make sure FastCGI can write to its log by changing permissions on the fcgi-log directory, e.g.:

$ chown wwwrun /srv/www/fcgi-log

Configure Apache httpd

Open the file /etc/sysconfig/apache2 in a text editor (or use YaST’s sysconfig editor). Look for the line that starts with APACHE_MODULES. Add the words “rewrite” and “fastcgi” to the quoted string (unless they are already present of course).

Next, add the following lines to /etc/apache2/httpd.conf:

AddHandler fastcgi-script fcgi

<Directory /srv/www/htdocs/>
  AllowOverride All
  Options FollowSymLinks
</Directory>

<Directory /srv/www/rails/*/public/>
  Allow from all
</Directory>

Test your configuration

Create a test application and symbolic link (the first chown is necessary for new session storage defaults in Rails 1.1):

$ cd /srv/www/rails
$ rails test
$ chown -R wwwrun:www test/tmp
$ chown -R wwwrun:www test/public
$ ln -s /srv/www/rails/test/public /srv/www/htdocs/test

Edit the file .htaccess in your new application’s public directory. Comment out the two AddHandler lines at the top of the file, and change dispatch.cgi to dispatch.fcgi.

Edit the file dispatch.fcgi in the same directory. Add the FastCGI log path and file name of your choice to the last line, e.g.:

RailsFCGIHandler.Process! '/srv/www/fcgi-log/test_fcgi_crash.log'

Finally, start Apache with the command:

rcapache2 start
and test by browsing to http://localhost/test/. Click on the link that says ”About your application’s environment” to make sure FastCGI works.

mod_fcgid

Many suggest that mod_fastcgi is unstable under Apache 2.0, and recommend using mod_fcgid instead.

Requirement
  • apache2-devel installed

There are different distributions of SUSE around, but under mine, compiling mod_fcgid was not as straightforward as some claim. Here is a script you can use, which illustrates the steps required on my (i64) SUSE distribution. This is only for educational purposes, and for Prefork MPM. I recommend doing each of these steps manually in case there are errors.

#!/bin/bash
wget http://fastcgi.coremail.cn/mod_fcgid.1.08.tar.gz
tar -xvzf mod_fcgid.1.08.tar.gz
cd mod_fcgid.1.08

#Changes Makefile so it point to /usr/share/apache2
sed -i.bk 's#^\(top_dir\s*=\s*\).*$#\1/usr/share/apache2#' Makefile

#Won't compile if apache2/include doesn't point to prefork.
if [[ `readlink /usr/share/apache2/include` != '/usr/include/apache2-prefork' ]]
then
  mv /usr/share/apache2/include /usr/share/apache2/include.bk
  ln -s /usr/include/apache2-prefork /usr/share/apache2/include
fi

make
strip .libs/mod_fcgid.so
make install

This module has otherwise little difference, configuration-wise, from mod_fastcgi. A basic configuration requires these additional steps:
  1. Edit the APACHE_MODULES line in /etc/sysconfig/apache2, inserting “fcgid” and removing “fastcgi” if necessary.
  2. Modify /etc/apache2/httpd.conf as above, changing the AddHandler... line for:
    SocketPath /tmp/fcgidsock
    AddHandler fcgid-script fcgi

or

  1. create a file /etc/apache2/conf.d/mod_fcgid.conf with
    
    <IfModule mod_fcgid.c>
      SocketPath /tmp/fcgidsock
      AddHandler fcgid-script fcgi
    </IfModule>
    

All other steps remain the same as for mod_fastcgi.

SUSE 10.0

These are step-by-step instructions for installing Ruby on Rails under SUSE Linux 10.0. A few things to keep in mind before we begin:

  • This guide is only good for a development environment. Many other factors will have to be considered for a production environment, and there are other pages and even an entire book to cover these.
  • I will not show you for the thousandth time how to install MySQL.
  • Of course, there are other ways to set things up, and there are multiple paths to the same setup. Feel free to experiment.
  • We will be using FastCGI under Apache 2.0, and it will be set up to handle Rails applications in subdirectories, instead of virtual hosts. I feel this is more appropriate for development, as you can add applications without reconfiguring Apache.
  • You need to be logged in as root for this procedure to work.

Install the necessary packages

Launch SUSE’s package manager, YaST, either from the GUI or from the command line (yast). Go into Software Management and use the Search function to locate packages called FastCGI and rubygems. If they are listed, skip the next paragraph.

If your current installation sources don’t include the required packages, go back to YaST’s main menu, and go into Installation Source. Disable your current source(s) and add a new source pointing to the OpenSUSE repository. You can find a list of repositories at OpenSUSE or you can Google for one. For example, add the FTP source suse.mirrors.tds.net, directory pub/opensuse/distribution/SL-10.0-OSS/inst-source. Once you’ve added the source, save your changes and go back into Software Management.

Using YaST, install (or keep) at least the following packages:
  • FastCGI
  • FastCGI-devel
  • apache2-mod_fastcgi (and apache2 itself of course)
  • ruby
  • ruby-doc-ri
  • rubygems
  • zlib

If a conflict dialog pops up, just add the required packages. Also make sure ruby-mysql and ruby-fcgi are unchecked, as we will install them using RubyGems.

Install Rails

As in other distributions, use RubyGems to install FastCGI and (optionally) MySQL bindings, as well as (of course) rails and its dependencies:

$ gem install fcgi
$ gem install mysql
$ gem install rails -y

Set up a directory structure

With SUSE, I like to work under the /srv directory, but you may of course adjust with your own paths. As an example, let’s create the following directories:

  • /srv/www/rails — we will put all our Rails applications under this directory.
  • /srv/www/fcgi-log — this will hold the FastCGI crash logs. This is necessary because we’ll be using symbolic links and I’ve found that this makes RoR’s default FastCGI log path invalid.

Also, make sure FastCGI can write to its log by changing permissions on the fcgi-log directory, e.g.:

$ chown wwwrun /srv/www/fcgi-log

Configure Apache httpd

Open the file /etc/sysconfig/apache2 in a text editor (or use YaST’s sysconfig editor). Look for the line that starts with APACHE_MODULES. Add the words “rewrite” and “fastcgi” to the quoted string (unless they are already present of course).

Next, add the following lines to /etc/apache2/httpd.conf:

AddHandler fastcgi-script fcgi

<Directory /srv/www/htdocs/>
  AllowOverride All
  Options FollowSymLinks
</Directory>

<Directory /srv/www/rails/*/public/>
  Allow from all
</Directory>

Test your configuration

Create a test application and symbolic link (the first chown is necessary for new session storage defaults in Rails 1.1):

$ cd /srv/www/rails
$ rails test
$ chown -R wwwrun:www test/tmp
$ chown -R wwwrun:www test/public
$ ln -s /srv/www/rails/test/public /srv/www/htdocs/test

Edit the file .htaccess in your new application’s public directory. Comment out the two AddHandler lines at the top of the file, and change dispatch.cgi to dispatch.fcgi.

Edit the file dispatch.fcgi in the same directory. Add the FastCGI log path and file name of your choice to the last line, e.g.:

RailsFCGIHandler.Process! '/srv/www/fcgi-log/test_fcgi_crash.log'

Finally, start Apache with the command:

rcapache2 start
and test by browsing to http://localhost/test/. Click on the link that says ”About your application’s environment” to make sure FastCGI works.

mod_fcgid

Many suggest that mod_fastcgi is unstable under Apache 2.0, and recommend using mod_fcgid instead.

Requirement
  • apache2-devel installed

There are different distributions of SUSE around, but under mine, compiling mod_fcgid was not as straightforward as some claim. Here is a script you can use, which illustrates the steps required on my (i64) SUSE distribution. This is only for educational purposes, and for Prefork MPM. I recommend doing each of these steps manually in case there are errors.

#!/bin/bash
wget http://fastcgi.coremail.cn/mod_fcgid.1.08.tar.gz
tar -xvzf mod_fcgid.1.08.tar.gz
cd mod_fcgid.1.08

#Changes Makefile so it point to /usr/share/apache2
sed -i.bk 's#^\(top_dir\s*=\s*\).*$#\1/usr/share/apache2#' Makefile

#Won't compile if apache2/include doesn't point to prefork.
if [[ `readlink /usr/share/apache2/include` != '/usr/include/apache2-prefork' ]]
then
  mv /usr/share/apache2/include /usr/share/apache2/include.bk
  ln -s /usr/include/apache2-prefork /usr/share/apache2/include
fi

make
strip .libs/mod_fcgid.so
make install

This module has otherwise little difference, configuration-wise, from mod_fastcgi. A basic configuration requires these additional steps:
  1. Edit the APACHE_MODULES line in /etc/sysconfig/apache2, inserting “fcgid” and removing “fastcgi” if necessary.
  2. Modify /etc/apache2/httpd.conf as above, changing the AddHandler... line for:
    SocketPath /tmp/fcgidsock
    AddHandler fcgid-script fcgi

or

  1. create a file /etc/apache2/conf.d/mod_fcgid.conf with
    
    <IfModule mod_fcgid.c>
      SocketPath /tmp/fcgidsock
      AddHandler fcgid-script fcgi
    </IfModule>
    

All other steps remain the same as for mod_fastcgi.