• Sales: 1-800-961-2888
  • Support: 1-800-961-4454

Ubuntu Hardy - using mod rails to serve your application


Following from the first article Ubuntu Hardy - mod_rails installation, 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.


Contents

Rails application

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

Done.

Virtual Host

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

sudo nano /etc/apache2/sites-available/testapp

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

</VirtualHost>

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.

Once done, we can enable the new site:

sudo a2ensite testapp

Rewrite

As you may know, Rails applications make use of an .htaccess file for various rewrite rules.

If this is a fresh Cloud Server and you do not have the Apache rewrite module enabled, now would be a good time to enable it:

sudo a2enmod rewrite

Reload

Finally, reload Apache:

sudo /etc/init.d/apache2 reload

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

Done.

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 to 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.

Summary

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.

Although it is relatively new, mod_rails offers a great deal to the Ruby on Rails community.

PickledOnion







© 2011-2013 Rackspace US, Inc.

Except where otherwise noted, content on this site is licensed under a Creative Commons Attribution-NonCommercial-NoDerivs 3.0 Unported License


See license specifics and DISCLAIMER