CentOS - using mod_rails to serve your application

Following from the first article, we now have passenger (mod_rails) installed.

As such, we can move on and create a Ruby on Rails application and see how easy it is to serve using passenger.

Rails application

As the default permissions only allow us, the 'demo' user, to browse our home folder, let's start off by giving Apache access to this folder as well:

chmod 755 /home/demo

Move into the public_html folder (if you don't have one, then simply create it):

cd ~/public_html

Then create a simple Ruby on Rails application:

rails testapp


Virtual Host

To serve the Rails application, we need to create a virtual host:

sudo nano /etc/httpd/conf/httpd.conf

Although already mentioned, one of the exciting things about mod_rails is that you don't need any special settings in the virtual host configuration.

The contents can be as simple as this:

<VirtualHost *:80>

  ServerName  domain1.com
  ServerAlias www.domain1.com

  DocumentRoot /home/demo/public_html/testapp/public


Of course, you can add custom log file locations and other settings but the main thing to understand is the lack of proxy and port settings.


Finally, we need to enable the new site by reloading Apache:

sudo /etc/init.d/httpd reload

Note: If you get any port and NameVirtualHost errors on reloading Apache, please ensure you read the Apache Virtual Hosts article.


Is that it?

Yup. It really is that simple to serve Ruby on Rails applications with passenger (mod_rails).

Additional Rails apps can be configured in the same way - create a vhost and it's done.

Changes to the application

Whenever you deploy changes to your application all you need to do is:

touch /home/demo/public_html/testapp/tmp/restart.txt

That will enable the new content to be served - the command can be used in Capistrano or any script you use to deploy your applications.


Phusion's passenger (mod_rails) is easy to install and even easier to use.

There are no ports or proxies or any other complicated configurations.

As you can see, mod_rails offers a great deal to the Ruby on Rails community.

Article Comments:

Diego Viola commented Thu Apr 23 10:02:03 UTC 2009:

Having a tmp/always_restart.txt is better than touching tmp/restart.txt all the time.

just in case commented Wed Jun 03 10:24:25 UTC 2009:

Just in case someone, like myself, keeps getting the "We're sorry but something went wrong" error when trying to see their test apps or even the "application environment" link from the starting welcome page...

Add the following line to your vhost:

    RailsEnv   development


Tony commented Fri Aug 14 00:27:13 UTC 2009:

after working through the install on a fresh slice, I cannot get apache to serve up rails. When I go to a URL that has an "index.html.erb" file, the page displays all the NON RUBY code just fine but does not seem to execute what is defined in the controller. script/server using Webrick (default w/ the install) seems to work just fine. Any ideas? Much appreciated.

Virtual host info below:

<virtualhost> ServerName shopihouse.com ServerAlias www.shopihouse.com DocumentRoot /root/public_html/shopihouse.com

# Custom log file locations LogLevel warn ErrorLog /root/public_html/<removed>.com/log/error.log CustomLog /root/public_html/<removed>.com/log/access.log combined RailsEnv development


Alex commented Thu Oct 04 13:24:39 UTC 2012:

After restarting Apache it said: DocumentRoot didn't exist. But it did (I got a 403 forbidden error). Turns out it was SELinux, turn it off with:

sudo setenforce 0

Then restart Apache.

Want to comment?

(not made public)


(use plain text or Markdown syntax)