User Guide - Ruby on Rails using mod_rails


Applicable Plans: All eApps General VPS Plans (CentOS 5 plans only)

User Guide – Ruby on Rails mod_rails User Guide

Phusion Passenger™ — a.k.a. mod_rails, makes deployment of Ruby web applications, such as those built on the revolutionary Ruby on Rails web framework, a breeze – from modrails.com

Overview

This User Guide is designed to get you started with mod_rails on your eApps hosting plan. This user guide only provides a brief overview, and is not a definitive resource. If you need more information than what is provided in this User Guide, you will want to reference the official mod_rails documentation.

mod_rails will allow you to host most any rack capable application, such as Sinatra and Camping. However, it is not possible for eApps to offer any support for these applications. Our support is limited to the actual install of mod_rails from the Control Panel, along with some very basic configuration.

If you need support for any of the various mod_rails and rack applications you are trying to install, please reference the documentation that came with the application, or any online resources for those applications. Any assistance from eApps support for the installation or configuration of these applications would be considered billable at our standard rate of $15 per 10 minutes.

The information in this User Guide is based on the assumption that you have already read the Ruby on Rails User Guide and have met all the Requirements. If you have not read that User Guide, please do so now. Reading and following that User Guide is the key to success with the information in this User Guide.


mod_rails is only available on plans using the CentOS 5 or greater operating system. To see what operating system (OS) you have, click on the Subscriptions icon from the My Account tab of your Control Panel. Then click on the name of the subscription you want to see. The OS for the subscription will be displayed near the top of the page. If you are not on a CentOS 5 plan, but would like information on updating your plan, please contact eApps Technical Support for more information.

Note mod_rails is the recommended approach for deploying your Ruby on Rails applications on the eApps service

Installing mod_rails
Deploying your application with mod_rails
Bypassing mod_rails to serve other applications
Managing Resources and Optimizations
Links to other information

Installing mod_rails

To install mod_rails, follow these steps:
Login to your Control Panel, and click on the System Tab. If necessary, click the Select Another System (Subscription) link on the left and choose the correct Virtuozzo system.

Go to Applications, and click on the Add Application link. Select the box next to Mod_rails, and then scroll down and click the Next button. If you need to also install Ruby on Rails, you can install it from this same screen.

This takes you back to the All Applications screen. Wait for five minutes, then click on the Refresh link at the upper right, just under the word Parallels. The application should now show as installed. If it is still in a Scheduled state, wait another five minutes, and click Refresh again. If you see it in Error state, or it still shows as Scheduled, please contact eApps Technical Support.


Deploying your application with mod_rails


Note The following are two deployment examples using mod_rails. Please see the official mod_rails documentation for further examples. These examples assume you have a Ruby on Rails application already created and uploaded to the VPS, and are able to login to the VPS using SSH, use standard Linux commands, and edit files in the vi text editor.

Deployment with your Ruby on Rails application being served at http://example.com or http://www.example.com


Log in to your Control Panel, and click on the System Tab. If necessary, click on the Select Another System (Subscription) link on the left and choose the correct Virtuozzo Container. Once the correct system name shows in the System Tab, click on the Site Tab. If you have more than one site, you may need to click on the Select Another Site link, and choose the correct site.

Once the correct site is selected, then click on Website Settings, then on the Custom Settings tab. Click Edit, and set the DocumentRoot of the site to the path of your Rails application. Remember that this is an example, your path and application name may be different. Please adjust accordingly.

DocumentRoot /home/webadmin/example.com/html/appname/public

Click Update to save the new DocumentRoot.

Deployment with your Ruby on Rails application being served at
http://example.com/myapp or http://www.example.com/myapp

Connect to the VPS using SSH as the user for the site that has the Ruby on Rails application. In this example, that user is webadmin and the site is example.com. Please substitute your username and site as necessary. Also, this example uses appname as the name of your Ruby on Rails application, and myapp as the name you want to use in the URL.  The names of the application and the name in the URL have to be different to allow the symbolic link that must be created.

[webadmin@example ~]$ cd example.com/html/
[webadmin@example html]$ ln -s /home/webadmin/example.com/html/appname/public/ /home/webadmin/example.com/html/myapp
(this should be on one line, with the space between public/ and /home)

[webadmin@example html]$ ll myapp
lrwxrwxrwx 1 webadmin webadmin 66 Oct 14 12:34 myapp -> /home/webadmin/example.com/html/hello/public/


Now add the necessary directives to the Custom Settings tab for that Site in the Control Panel. Log in to your Control Panel, and click on the System Tab. If necessary, click on the Select Another System (Subscription) link on the left and choose the correct Virtuozzo Container. Once the correct system name shows in the System Tab, click on the Site Tab. If you have more than one site, you may need to click on the Select Another Site link, and choose the correct site.

Once the correct site is selected, then click on Website Settings, then on the Custom Settings tab. Click Edit, and add this line:

RailsBaseURI /myapp

Click Update to save the new settings.


Bypassing mod_rails to serve other applications 

If you wish to serve other applications from your web site, such as Wordpress or Joomla or Open Webmail, you will need to bypass mod_rails so that Apache can serve those applications directly.

To do this, add a section to the Custom Settings tab for the Site. Substitute the name of the application you are trying to serve for example_app.  

To add the necessary directives to the Custom Settings tab for that Site in the Control Panel.
Log in to your Control Panel, and click on the System Tab. If necessary, click on the Select Another System (Subscription) link on the left and choose the correct Virtuozzo Container. Once the correct system name shows in the System Tab, click on the Site Tab. If you have more than one site, you may need to click on the Select Another Site link, and choose the correct site.

Once the correct site is selected, then click on Website Settings, then on the Custom Settings tab. Click Edit, and add the appropriate lines. Click Update to save the settings.

<Location /example_app>
PassengerEnabled off
AllowOverride all
</Location>

You can also add several Location blocks in a row for multiple applications.

<Location /example_app>
PassengerEnabled off
AllowOverride all
</Location>
<Location /other_example_app>
PassengerEnabled off
AllowOverride all
</Location>

Here is a list of most of the applications offered by eApps so that you can set the Location names correctly.

/webmail - Roundcube or Squirrelmail
/mail - Open Webmail
/awstats - Awstats
/myadmin - phpMyAdmin
/pgadmin - phpPgAdmin
/cgi-bin - cgi-bin directory
/openwebmail - Open Webmail
/joomla - Joomla
/wordpress - Wordpress
/drupal - Drupal
/mailman - Mailman
/spamassassin - Spamassassin

Managing Resources and Optimizations

mod_rails provide three directives for managing web server resources for your Rails application. These directives are PassengerMaxPoolSize, PassengerMaxInstancePerApp and PassengerPoolIdleTime.
  • PassengerMaxPoolSize – this is the maximum number of Ruby on Rails application instances that may be active at the same time. The default value for this directive without any configurations is 6. Memory and CPU must be considered when increasing this value. The higher the value the higher the memory usage. A recommended value for this directive is 2 for those using 256 MB of RAM or below though resources are not consumed until instances are spawned.
  • PassengerMaxInstancesPerApp – maximum number of instances that may be active for a single application. This value helps to keep a single application from using all available instances in the PassengerMaxPoolSize. This value must also been less then the PassangerMaxPoolSize and the default is 0. A value of 0 means unlimited which is a result of each application having access to instances up to the PassengerMaxPoolSize.
  • PassengerPoolIdleTime – Maximum number of seconds a application instance can be idle. If an application instance has not done anything after this idle time then it will be shutdown to conserve resources. Setting the value too low means your application will have to be spawned more often. This may cause some slowness since the processes of spawning is relatively slow. The recommended value is 2 * x where x is the average number of seconds a visitor is expected to spend on a single Rails web page. The default value for this directive is 300.
These directives are applied to the Apache Web Server global configuration. To make make changes to the default values above you will need to modify the file /etc/httpd/conf.d/passenger.conf.

Note All of the following must be done from the command line of the VPS while logged in via SSH as the root user. See the SSH User Guide for more information if necessary. The ability to use standard Linux commands and edit files using the vi text editor is required. 

This example sets PassengerMaxPoolSize to 4, PassengerMaxInstancesPerApp 2 and PassengerPoolIdleTime to 400

[root@example ~]# cd /etc/httpd/conf.d
[root@example conf.d]# vi passenger.conf

Edit passenger.conf, changing the file from:

LoadModule passenger_module /usr/share/passenger/ext/apache2/mod_passenger.so
PassengerRoot /usr/share/passenger
PassengerRuby /usr/bin/ruby

to:

LoadModule passenger_module /usr/share/passenger/ext/apache2/mod_passenger.so
PassengerRoot /usr/share/passenger
PassengerRuby /usr/bin/ruby
PassengerMaxPoolSize 4
PassengerMaxInstancesParApp 2
PassengerPoolIdleTime 400

and  save and exit the file. Then, restart the Apache web server.

[root@example conf.d]# service httpd restart
Stopping httpd:                                            [  OK  ]
Starting httpd:                                            [  OK  ]
[root@example conf.d]#


Links to Other Information

Ruby on Rails Wiki - http://wiki.rubyonrails.org/
Official mod_rails main documentation site - http://modrails.com/documentation.html

mod_rails User Guide, Apache version - http://modrails.com/documentation/Users%20guide%20Apache.html
mod_rails (Phusion Passenger) main site - http://modrails.com/

Comments

Please login to comment