Deploying a Rails Application With Passenger

From OCS Support Wiki

Jump to: navigation, search

Contents

[edit] Introduction

This guide will show you how to deploy your Rails application with mod_rails on our Webmin and cPanel servers. This is by far the easiest way to deploy your Rails application, and is now the recommended method of deployment.

[edit] cPanel

[edit] Upload Your Existing Application

To use an existing Rails application with mod_passenger on our cPanel servers, simply upload it to a directory in your home directory (we recommend rails_apps/yourapp, where yourapp is a short name for your application). You will also need to setup your database settings if you have not already done so.

[edit] Symlinking the Public Folder

NOTE: The following instructions assume that you want to deploy your Rails application so that it takes over the entire site. If you want to deploy it to a sub folder, please see the instructions below pertaining to deploying to a sub folder.

Since you can't change the document root on cPanel, a symlink is necessary to link the public folder in your Rails application to the public_html folder that the web server serves. To do this, change the values below to suit your application name and run:

cd ~
mv public_html original_public_html
ln -s rails_apps/yourapp/public public_html

Remove the .htaccess file in the public directory of your Rails application, and the app should now run correctly when you go to the site in your browser.

[edit] Deploying to a Sub Folder

NOTE: If you have already deployed it on the main site above, you cannot follow these instructions. You must start again with these instructions.

If you want to have your Rails application hosted at (for example) http://www.yoursite.com/myrails/ instead of the default http://www.yoursite.com/, you will need to perform all of the following above, except via SSH run:

cd ~
ln -s rails_apps/yourapp/public public_html/myrails
cd ~/public_html

Replace yourapp with the correct name of your application and myrails with the sub folder you want to have host your Rails application.

[edit] Webmin

[edit] Upload Your Existing Application

To use an existing Rails application with mod_rails on our Webmin servers, simply upload it to a folder in your home directory (not in the public_html folder on the server though). You will also need to setup your database settings if you have not already done so. This guide does not cover this section.

[edit] Changing the Document Root

Changing the document root is probably the simplest way to activate mod_rails for your Rails application.

In Webmin, click on Configure Website under Services as shown below:

Image:ChangeDocRoot1.jpg

Click on Document Options and then click the browse icon on the document options form, as shown below:

Image:ChangeDocRoot2.jpg

Select the public folder from your Rails application. In our example above, this would be in the myapp/public folder.

Click Save, then Apply Changes in the top right-hand corner of the page.

Your Rails application should now work correctly.

[edit] Using a symlink

You can also use a symlink to link the existing public_html folder, which is there by default, to another area. This is a more advanced method. You can do something similar to:

cd ~
mv public_html original_public_html
ln -s myapp/public public_html

to achieve the symlink. If in doubt, use the changing document root method above.