How Do I Start Using Ruby on Rails?

At Pawnhost you get fast and reliable server backed by our unconditional personal support.
Lets start!

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.

    Be sure to give it a name. In this instance, we'll call the application Redmine since it will be hosting a Redmine application.
    cPanel will fill in the application path, so just check the box for Load on Boot?
    Set the environment to Production.
    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 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:

    Delete the redmine directory in its entirety.
    Rename the directory you unzipped to redmine. Essentially, we're replacing the default cPanel redmine directory with our downloaded one.
    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.

    Under the Create New Database section, make a new database.
    Choose a name for your MySQL database
    Click on Create Database as in the below figure:
    In the example, we'll call it redmine. Also, create a MySQL user.
    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
    Next, in the Add User To Database section, let's add our user to our redmine database.
    Select your user from the drop-down menu.
    Select your database from the drop-down menu.
    Click Add.
    Adding User to Database
    In the next screen that appears, select the box for All Privileges.

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. We'll be executing some commands from SSH, and these are required for the application to function correctly.

    Connect to your account via SSH.

    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
    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
    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
    Go ahead and edit the settings under the production section. Here's an example of what the settings look like:
    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:

    Execute the following code in SSH:
    rake generate_session_store
    Next, execute the following. It will create tables and an administrator account:
    RAILS_ENV=production rake db:migrate
    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.

    Go to your Ruby on Rails control panel and look under the Create A Rewrite section.
    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.
    BestHost 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.
    Go back to cPanel and head to your File Manager.
    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.
    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} ^$ [OR]
    RewriteCond %{HTTP_HOST} ^$
    RewriteRule ^/?$ "{REQUEST_URI}" [P,QSA,L]
    Change the following line:
    RewriteRule ^/?$ "{REQUEST_URI}" [P,QSA,L]

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

    Note the change in the second set of characters ==> ^/?$ to ^(.*)$
    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.

  • 110 Users Found This Useful
Was this answer helpful?

Related Articles

How to Generate Full Backup

Full BackupHome Directory BackupA full backup of any account generates a copy of your files,...

SSH for shared hosting

Login to the cPanel that you want to connect to using SSH. Under Security click SSH Access....