Posts Tagged ‘passenger’

Preparing Ruby on Rails environment – using apache for development

February 6th, 2009 Comments off

In previous post we have created first rails application, it was tested using WEBrick which is part of rails environment. To have environment more similar to server environment and to get rid of keeping track of started projects we will switch to running applications with apache and passenger. There are some benefits of this configuration:

  1. Possibility to run all applications with only one server,
  2. Easy to share applications on local network or even to Internet,
  3. Fast detection of problems with compatibility to passenger,
  4. There are probably more benefits, If You know them leave me a comment.

So lets start with configuration, on beginning turn off apache:

/etc/init.d/apache2 stop

As a central point of configuration we will use ~/public in my case it is /home/mpapis/public, we need to create this directory:

mkdir /home/mpapis/public

Configure Your /etc/hosts to have some meaningful name for running it in the browser, so edit /etc/hosts and modify Your localhost line to look similar to this one (added rails):       localhost  rails

We need to configure apache to respond to our requests, first remove or backup default vhost configuration:

cd /etc/apache2/vhosts.d

mv 00_default_vhost.conf 00_default_vhost.conf.old

After getting rid of default configuration we can edit apache/passenger configuration file created in one of previous posts /etc/apache2/vhosts.d/01_passenger.conf:

LoadModule passenger_module /usr/lib64/ruby/gems/1.8/gems/passenger-2.0.6/ext/apache2/
PassengerRoot /usr/lib64/ruby/gems/1.8/gems/passenger-2.0.6
PassengerRuby /usr/bin/ruby18

UseCanonicalName Off
DocumentRoot /home/mpapis/public
ServerName rails
ServerAlias localhost
RailsEnv development
Include /home/mpapis/public/paths.conf
<Directory “/home/mpapis/NetBeansProjects”>
Options -Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
Allow from all
<Directory “/home/mpapis/public”>
Options -Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
Allow from all

One of the lines defines that we will use /home/mpapis/public/paths.conf as part of the configuration, and this is the contents of this file:

RailsBaseURI /RailsApplication1

As we pointed /home/mpapis/public in previous file as document root and /RailsApplication1 as path of our application we need to create symbolic link to our application:

ln -s /home/mpapis/NetBeansProjects/RailsApplication1/public/ /home/mpapis/public/RailsApplication1

Last step is to notify our application that it will no more run from the / path, so we add the following entry to /home/mpapis/NetBeansProjects/RailsApplication1/config/environments/development.rb:

config.action_controller.relative_url_root = “/RailsApplication1”

That’s all, we can start appache now:

/etc/init.d/apache2 start

And if it is desired add it to autostart (to have our applications available just after system boot):

rc-update add apache2 default

Finally we can check work of our application by navigating in web browser window to the following path:


Looks pretty nice, in next step we will need to automate this a bit to avoid manual work each new project:

Rails try to follow DRY which stands for “don’t repeat yourself”.

Categories: Development, Linux Tags: , , , ,

Preparing Ruby on Rails environment – apache, ruby

January 24th, 2009 Comments off

In previous article I have described how to setup postgress for development, now is time to continue with the environment. At the beginning we need:

  • ruby as it is base for rails,
  • apache For serving pages,
  • java + netbeans for development.

So installation of required system packages:

emerge -qDNu ruby rubygems apache jdk

/etc/init.d/apache2 start

Install ruby gems that will be needed shortly:

UPDATE: 2009.01.26 added postgres

gem install rails capistrano capistrano-ext passenger postgres

Now we need to integrate passenger into apache – please run:


UPDATED 2009-02-06:

The installation should go without nay problems (If You followed all instructions), at the end You will be asked to modify apache configuration file – few Lines of the output – starting with LoadModule, PassengerRoot and PassengerRuby – should be copied to new apache configuration file, easiest way is to use this commands:

echo “LoadModule passenger_module /usr/lib64/ruby/gems/1.8/gems/passenger-2.0.6/ext/apache2/” > /etc/apache2/vhosts.d/01_passenger.conf

echo “PassengerRoot /usr/lib64/ruby/gems/1.8/gems/passenger-2.0.6” >> /etc/apache2/vhosts.d/01_passenger.conf

echo “PassengerRuby /usr/bin/ruby18” >> /etc/apache2/vhosts.d/01_passenger.conf

Some of the lines may differ from the output form yours passenger so please use Yours as it is better for you.

In next part we will continue with development environment.