How Do I Start Using Ruby on Rails?

Step 1: Setup Your Rails Environment

First, we're going to need to create the environment in which our rails application will live. Head to your cPanel and access the Ruby on Rails icon from the Software/Services section.

From the Ruby on Rails control panel, users will be able to create an application environment.

  1. Be sure to give it a name. In this instance, we'll call the application Redmine since it will be hosting a Redmine application.
  2. cPanel will fill in the application path, so just check the box for Load on Boot?
  3. Set the environment to Production.
  4. Click Create.
    Managing Ruby

This will create a directory at /home/[your username]/rails_apps/[app name]. Since the username is cubecity, this directory is called /home/cubecity/rails_apps/redmine.

Note: It's best to install this on a domain or subdomain as Redmine will often not work correctly with the default rewrite in a subfolder.

Step 2: Download & Extract the Application

First, head to your application's webpage and download the application. In this instance, we'll go http://rubyforge.org/projects/redmine/ to download Redmine.

Upload your application zip file to your rails_apps directory in your home directory as shown in the folllowing figure.

Application Zip Files

Unzipping the File

Unzipping Zip Files

This next part goes as follows:

  1. Delete the redmine directory in its entirety.
  2. Rename the directory you unzipped to redmine. Essentially, we're replacing the default cPanel redmine directory with our downloaded one.
  3. Delete your zip file for basic housekeeping. See the following figure for clarification.
    Editing the Zip Files

Now we're done with step two. Let's set up our database.


Step 3: Set Up the Database & Database User

Head back to cPanel. Go to MySQL Databases under the Databases section.

First, let's create a new MySQL database.

  1. Under the Create New Database section, make a new database.
  2. Choose a name for your MySQL database
  3. Click on Create Database as in the below figure:
    Databases
    In the example, we'll call it redmine. Also, create a MySQL user.
  4. Scroll down to the MySQL Users section, and begin filling out your desired database user credentials. We will also call the user redmine. Check out the figure below for more information:
    Assigning the Database
  5. Next, in the Add User To Database section, let's add our user to our redmine database.
  6. Select your user from the drop-down menu.
  7. Select your database from the drop-down menu.
  8. Click Add.
    Adding User to Database
  9. In the next screen that appears, select the box for All Privileges.
    Priveleges

Now, we have our database done. Let's hook Rails up to this.


Step 4: Connect Rails to The Database

This next section requires knowledge of SSH and how to connect to the server with a client such as PuTTY.

Instructions on configuring your SSH access can be found in this article:

We'll be executing some commands from SSH, and these are required for the application to function correctly.

  1. Connect to your account via SSH. You should be looking at a screen similar to this:
  2. PuTTY
  3. Change directories to your rails_apps/redmine directory (or whatever you named your rails app in step one. You can do this by executing the following command:
    cd rails_apps/redmine
  4. Copy config/database.yml.example to config/database.yml and edit this file in order to configure your database settings for "production" environment. Do this with the following command:
    cp config/database.yml.example config/database.yml
  5. Edit the file to add our MySQL credentials we created in step three. Execute the following command:
    nano config/database.yml

    You should see a screen that looks similar to this:
    PuTTY config

  6. Go ahead and edit the settings under the production section. Here's an example of what the settings look like:
    production:
    adapter: mysql
    database: cubecity_redmine
    host: localhost
    username: cubecity_redmine
    password: q1w2e3r4

Instead of 'cubecity' you'll use your own username. The rest of this step for Redmine is reposted from Redmine's guide for installing:

  1. Execute the following code in SSH:
    rake generate_session_store
  2. Next, execute the following. It will create tables and an administrator account:
    RAILS_ENV=production rake db:migrate
  3. Insert default configuration data in database, by running the following command:
    RAILS_ENV=production rake redmine:load_default_data

Step 5: Create Redirects

Start by heading back to cPanel.

  1. Go to your Ruby on Rails control panel and look under the Create A Rewrite section.
  2. Click the Create Rewrite button to create a rewrite for your application. This will create a .htaccess file in the directory of the domain you choose.
    HostGator doesn't recommend installing rails applications to subdirectories unless you are experienced with Ruby on Rails. Note which domain you rewrite the site to, so that you can to make a brief change to its .htaccess file.
  3. Go back to cPanel and head to your File Manager.
  4. In the Directory Selection popup, select Document Root for:, choose the domain you chose for your rewrite, make sure that Show Hidden Files is checked, and click Go.
  5. Select the .htaccess file, and select Edit. You should see the following (or something similar, depending on what your domain is.):
    RewriteEngine on

    RewriteCond %{HTTP_HOST} ^rails.hgfix.net$ [OR]
    RewriteCond %{HTTP_HOST} ^www.rails.hgfix.net$
    RewriteRule ^/?$ "http://127.0.0.1:12001%{REQUEST_URI}" [P,QSA,L]
  6. Change the following line:
    RewriteRule ^/?$ "http://127.0.0.1:12001%{REQUEST_URI}" [P,QSA,L]

    To match the line listed below:
    RewriteRule ^(.*)$ "http://127.0.0.1:12001%{REQUEST_URI}" [P,QSA,L]

    Note the change in the second set of characters ==> ^/?$ to ^(.*)$
  7. Click Save Changes.

Step 6: Run application

At this point, everything should theoretically run by browsing to the domain at which you installed your rails application.