Ruby on Rails

How do i View, Stop and Start my Ruby app via SSH

February 11th, 2010

To stop a process:
You can kill the process using kill -9

To view all processes:
You can view all running processes with ps ffaux the second column will be the pid.

Once the application has stopped you can start the application by running scripts/server -p in the directory of the RoR project.

Getting your LocalHost Ruby app working on the Server

February 10th, 2010

SSH Access

You will have to have to request jailed SSH access on your hosting account by submiting a support ticket. You can then use SSH to execute commands (rake, script/generate etc) like you would locally.

To log in to SSH run:

ssh -p 2222

Creating Application

Even though you have created your app locally, you want to create a new app in SSH (and let it create the folder hierarchy) and then replace all the controllers/views/models/db/config etc with your app.

To create the new app in SSH:
First navigate to a location where you want to create the new app folder – it doesn’t matter where, although cpanel likes to put them in ~/etc/rails_apps/.

rails -d mysql --with-dispatchers mynewapp

You now need to upload your locally created app to the server using FTP or otherwise. Don’t overwrite the files yet! Create another folder out of the way and upload it there for now. You have to be careful when overwriting the ssh created app that you don’t accidentally wipe some necessary files.

You can completely overwrite all files and folders EXCEPT the public folder. When dealing with the public folder, I suggest you overwrite the individual images, stylesheets and javascripts folders without touching the files already in /public/.

Specifically: public/dispatch.rb , public/dispatch.cgi and public/dispatch.fcgi must all be present otherwise your app will not function.

Once you’ve got your locally created app in place go on..


To get the app running properly it is necessary to edit .htaccess.
Navigate to ~/etc/rails_apps/mynewapp/public:

cd /etc/rails_apps/mynewapp/public

To open .htaccess

pico .htaccess

Regardless of whether there’s already text in the file or its blank, the only necessary code is as follows:

AddHandler fcgid-script .fcgi 
AddHandler cgi-script .cgi 
Options +FollowSymLinks +ExecCGI 
RewriteEngine On 
RewriteCond %{REQUEST_URI} ^/notrails.* 
RewriteRule .* - [L] 
RewriteRule ^$ index.html [QSA] 
RewriteRule ^([^.]+)$ $1.html [QSA]     
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteRule ^(.*)$ dispatch.fcgi [QSA,L]

Save the .htaccess file

Database Setup

In cpanel go to MySQL databases and create a new database:
eg. New database: records

Note that cpanel will automatically add username_ to the front of it, thus database name is:
You also need to create a user for this database:
eg. Username: gkumar
pw: *****
Note that cpanel will also append username_ to the front of each user too, thus database user will be:

Finally in cpanel Add user to database: username_gkumar to username_records.

You can now use this database, username and password in database.yml


in SSH or filemanager:

cd /etc/rails_apps/mynewapp/config/
pico database.yml

Setup database.yml for above example:

pool: 5
timeout: 5000
adapter: mysql
database: username_records
username: username_gkumar
password: *******
socket: /var/lib/mysql/mysql.sock
# Warning: The database defined as "test" will be erased and
# re-generated from your development database when you run "rake".
# Do not set this db to the same as development or production.
adapter: sqlite3
database: db/test.sqlite3
pool: 5
timeout: 5000
adapter: mysql
username: username_gkumar
password: *******
socket: /var/lib/mysql/mysql.sock
pool: 5
timeout: 5000
reconnect: true
socket: /var/lib/mysql/mysql.sock

Note: Leave test alone (if you setup test like the prod and dev you might accidentally wipe the database if you run a test). Take note of the adapter and socket, they need to be setup for mysql not sqlite.


Currently we have the app loaded at /etc/rails_apps/mynewapp. However, pages that are visible on the web need to be in the /public_html/ directory. Because of the way rails separates public from models/views etc, we use a sym link to make the files from /mynewapp/public appear also in /public_html/. It will essentially seem like the one folder (public) has 2 different paths to it.

Do you want the app to be displayed at or Do you have addon-domains or is this your only domain?

Case: Display at and yes I have addon domains

If we want to display at we need to create a symlink to /public_html/. The issue is that you must delete public_html and then recreate it with the symlink. (can’t symlink to an existing folder) As you probably know, addon domains are stored in /public_html/ To ensure that you don’t loose you addon domain data it is necessary to:

1. Copy the folder/s elsewhere
2. Delete public_html
3. Create the symlink (which will recreate /public_html)
4. Copy the folder/s back to their original location

So assuming you’ve backed up you addon domains and deleted public_html:

In SSH (at /home/username/) execute:

ln -s ~/etc/rails_apps/mynewapp/public ~/public_html

You will now find that in public_html you have the files and folders (images/stylesheets etc..) that are located in /mynewapp/public. Don’t forget to copy back you addon domains.

This is the hardest scenario, if you have no addon domains – obviously the same procedure applies without needing to backup anything.

If you want the rails app to display on an addon domain:

ln -s ~/etc/rails_apps/mynewapp/public ~/public_html/

If you want the rails app to display at (ensure no folder named blog exists)

ln -s ~/etc/rails_apps/mynewapp/public ~/public_html/blog

Also add to mynewapp/config/environment.rb:



At the top of the file you can add:

ENV['RAILS_ENV'] ||= 'production'

In the do |config| block:

config.load_paths += %W( #{RAILS_ROOT}/vendor/plugins )


You can also have problems if you are using gems in your app that SpeedHost hasn’t got installed. You can view which gems are installed in cpanel RubyGems and also install gems through cpanel. If there is a gem missing from our server, you can send us an email and we will have it installed on the server.

How do i Install Ruby Gems on my Hosting?

February 7th, 2010

Most Ruby (RoR) Gems are already installed on our servers and can we used by you, however there might be some specialized gems which you may want to install. This can be simply done by the command below.

run gem install <gem name>

If you have any problem, you can always raise a support ticket and we will have our Ruby admin install the gem for you.

Steps you can Perform to Deploy a Demo Rail Application

February 6th, 2010

1. Login to your SSH using your own account.
2. Once logged in make sure you are in your /home/username folder using the “pwd” command.

It should show the output like this:

cpaneluser@server [~]# pwd

3. Then run the following commands to generate a demo rail app and its controller.

cpaneluser@server [~]# rails /home/cpaneluser/demoapp
cpaneluser@server [~]# cd demoapp
cpaneluser@server [~]# ruby script/generate controller test

4. Now create a symlink in public_html so that the app is viewable via the web.

cpaneluser@server [~]# cd ../public_html
cpaneluser@server [~]# ln –s ../demoapp/public rails

5. Before you test the Rails page, there is one more modification you need to make.

cpaneluser@server [~]# cd ../demoapp/public
cpaneluser@server [~]# pico .htaccess

Locate the line where it has the code like below:

RewriteRule ^(.*)$ dispatch.fcgi [QSA,L]

Change that code to:

RewriteRule ^(.*)$ dispatch.cgi [QSA,L]

You can then visit and you should see a “Welcome Aboard” page which confirms successful working of your rail app. You can deploy any other standard Rail applications as well. Most of them should work well with the preinstalled Gems we have.

Ruby on Rails Gems Installed on our Server

February 5th, 2010

The following Gems have been preinstalled with the Ruby installations. Custom gems are avaliable on a per request basis. If you need an additional gem installed, please create a support ticket.

Service layer for easy email delivery and testing.

Web-flow and rendering framework putting the VC in MVC.

Web service support for Action Pack.

Implements the ActiveRecord pattern for ORM.

Support and utility classes used by the Rails framework.

BlueCloth is a Ruby implementation of Markdown, a text-to-HTML conversion tool for web writers. Markdown allows you to write using an easy-to-read, easy-to-write plain text format, then convert it to structurally valid XHTML (or HTML).

Builders for MarkUp.

A toolkit to create and control daemons in different ways

Parsing, generation, and caching system for xml news feeds.

A plugin system based only on rubygems that uses dependencies only

Utility library to aid in interacting with gnuplot

This is a Ruby library for building trees representing HTML structure.

A small fast HTTP library and server that runs Rails, Camping, and Nitro apps.

MySQL/Ruby provides the same functions for Ruby programs that the MySQL C API provides for C programs.

Payment is used to process credit cards and electronic cash through merchant accounts.

Web-application framework with template engine, control-flow layer and ORM.

Ruby based make-like utility.

This package provides download sources for remote gem installation

Ruby interface to HTML Tidy Library Project

Generation of UUIDs.

A very simple API for XML processing.

We are offering jailed SSH access on all our servers. You can get SSH enabled for your account if you want to deploy and test Rails applications rapidly. The procedure to get SSH access is simple. You can order SSH while you are taking hosting from us or later by raising a support ticket from SpeedHost admin area.