Results 1 to 10 of 10

Thread: [How To] - Create a Ruby on Rails Application Using cPanel

  1. #1
    Matt's Avatar
    Matt is offline GlowHost Administrator
    Join Date
    Jan 2005
    Location
    Behind your monitor
    Posts
    6,236

    Default [How To] - Create a Ruby on Rails Application Using cPanel

    Getting Started

    To make your first Ruby on Rails application using cPanel, follow these simple steps.

    1. Login to cPanel.
    2. Click on the icon for "Ruby on Rails" (not Ruby Gems)
    3. Check the box for "Load on boot?'
    4. Fill in the "App Name" box and name it "test"
    5. Application Path will be automagically filled in for you as public_html/test
    6. Select "production" for the Environment, which should already be selected as the default.
    7. Click "Create"

    8. Now you can go to http://yourdomain.com/test/public/

    You should now see a "Welcome aboard" message which is the default Ruby index page.

    If you get a 400 Error, make sure to include the trailing slash "/" after "public" or you may not see the default Rails welcome page.

    Example:
    http://domain.com/test/public <-- BAD
    http://domain.com/test/public/ <-- GOOD

    Congratulations, you have setup the basic framework for your new RoR application using cPanel!
    Send your friends and site visitors to GlowHost and get $125 plus bonus!
    GlowHost Affiliate Program | Read our Blog | Follow us on X |

  2. #2
    Matt's Avatar
    Matt is offline GlowHost Administrator
    Join Date
    Jan 2005
    Location
    Behind your monitor
    Posts
    6,236

    Default

    Your First Ruby on Rails Program

    Now that you have created your RoR framework we will make a very basic RoR program. For this tutorial we will be using Pico, Putty and Windows.

    Windows is obviously an Operating System (OS), this tutorial assumes it is the OS running on the computer you are viewing this page in.

    Putty is the SSH program for connecting to the Linux server from Windows using SSH.

    Pico is a Linux text editor.

    You are going to need a shell account for this to work, so if you do not already have one, please contact support so that we can enable a jailshell for your account.

    Login to your jailshell account using Putty (or your favorite SSH program) using your cPanel username and password. Once logged in, navigate to your "test" directory that we created in the previous tutorial. For simplicity, you can copy and paste the commands below into your terminal session.

    From the commandline type in "cd public_html/test" then press enter.
    Code:
    cPanel-user@server [~]# cd public_html/test
    You just changed directories (cd) to your "test" directory.

    Next execute this command from your Rails application directory ("test") to generate your Rails controller:

    Code:
    cPanel-user@server [~/public_html/test]# ruby script/generate controller hello index
    Now you need to build your program. You can use notepad or some other text editor, and upload the file, or you can edit it right in your shell using pico.

    Code:
    cPanel-user@server [~/public_html/test]# pico app/controllers/hello_controller.rb
    You are now using the Pico text editor.

    You will see something similar to:

    Code:
    class HelloController < ApplicationController
     
      def index
      end
    end
    Change this files so that it appears like the below:

    Code:
    class HelloController < ApplicationController
     
      def world
      @greeting = "hello world!"
      end
    end
    Press ctrl+x and type "y" for yes, then press enter to write to the file.

    "def world" is a method called whenever users request yourwebsite.com/hello/world

    @greeting is a variable, and is also an object. The @ means it will be seen by the code in your application until the end of the request. We will be using it later in the view.

    Finally we need to make the file "world.rhtml" in app/views/hello/world.rhtml by using Pico again:

    Code:
    cPanel-user@server [~/public_html/test]# pico app/views/hello/world.rhtml
    You will be looking at an empty file. Add this line of code to it, then save and exit.

    Code:
    <&#37;= @greeting %>
    Now go back to your cPanel > Ruby on Rails and make sure your application is running. If it is showing as "Not Running" you can click the "Run" button in the "Actions" column for "Available Ruby on Rails Applications."

    Once you have started the application, you can view it on the web, here:

    http://domain.com/test/public/hello/world/
    (domain.com is your actual domain)

    If you would like to shorten the URL up a bit, you can symlink it like so:

    Code:
    cPanel-user@server [~/public_html/test]# cd ../
    cPanel-user@server [~/public_html]# ln -s /home/cPanel-user/public_html/test/public new
    Now you can access the app at http://domain.com/new/hello/world

    If you have any questions or comments, or would like to add to this tutorial, please, feel free! Just hit the "Post Reply' button below.
    Last edited by Matt; 10-31-2007 at 01:43 AM.
    Send your friends and site visitors to GlowHost and get $125 plus bonus!
    GlowHost Affiliate Program | Read our Blog | Follow us on X |

  3. #3
    mm2001 is offline Newbie
    Join Date
    Oct 2007
    Posts
    2

    Default

    Some useful steps after getting hello world running as described above are:

    - remove or rename test/public/index.html to remove the default Ruby on Rails welcome page

    - Modify test/config/routes.rb and add the line

    Code:
    map.connect '', :controller => "hello"
    so the default url of http://domain.com/test/public/ does something useful (Note, the trailing '/' is very important!)

    To provide database access, you need to:

    - create a database via cpanel
    - edit the file test/config/database.yml using the database you created with the name in the form of cpanelname_dbname.

    Thanks for the tutorial Matt, its going to save a lot of people a lot of time!

  4. #4
    yagnesh is offline Newbie
    Join Date
    May 2008
    Posts
    1

    Default

    Nice tutorial,
    but how i host my made rails application in cpanel?
    can u give me guidence for that?
    Thanks in advance
    Yagnesh

  5. #5
    Support7 is offline Newbie
    Join Date
    Aug 2010
    Posts
    1

    Default

    Matt,

    I followed the same steps but when I try to access http://domain.com/test/public/hello/world/ I get 404 error, I've confirmed the status for the Ruby on Rails app is running in cpanel

    Could you please help me what is wrong ?

    Thanks

  6. #6
    Matt's Avatar
    Matt is offline GlowHost Administrator
    Join Date
    Jan 2005
    Location
    Behind your monitor
    Posts
    6,236

    Default

    Well, I hate to ask the obvious, but are you using your own domain or are you using "domain.com" to access your ruby app? (I do see a 404 at the example URL, so I figured I would ask)

    Aside from that, I am not sure exactly what the problem might be. This thread was started in 2007 so there have been many changes in the way Ruby is integrated with cPanel, and the way that RoR works has likely changed quite a bit.

    If you are using your actual domain, you might search the web for a newer tutorial and post back here if you get things working.

    I have not really dabbled in RoR in quite some time so I am afraid I don't have any good answers for you.
    Send your friends and site visitors to GlowHost and get $125 plus bonus!
    GlowHost Affiliate Program | Read our Blog | Follow us on X |

  7. #7
    Join Date
    Oct 2010
    Posts
    2

    Default my server is not running. how come? how can I run my server manually?

    I already have RoR application, but on my cpanel I can't start the server. how do I do it?

  8. #8
    Matt's Avatar
    Matt is offline GlowHost Administrator
    Join Date
    Jan 2005
    Location
    Behind your monitor
    Posts
    6,236

    Default

    Usually, you just click on the "run" icon in the list of RoR applications.
    Send your friends and site visitors to GlowHost and get $125 plus bonus!
    GlowHost Affiliate Program | Read our Blog | Follow us on X |

  9. #9
    Join Date
    Oct 2010
    Posts
    2

    Default

    Quote Originally Posted by Matt View Post
    Usually, you just click on the "run" icon in the list of RoR applications.
    I tried. It won't run. Do I have to run the server using command line? how do I do it?

  10. #10
    Matt's Avatar
    Matt is offline GlowHost Administrator
    Join Date
    Jan 2005
    Location
    Behind your monitor
    Posts
    6,236

    Default

    It should run using cPanel. If it does not then perhaps we need to have cPanel support take a look at it. Please log a ticket at our helpdesk with any relevant information to your account so that we an have a look.
    Send your friends and site visitors to GlowHost and get $125 plus bonus!
    GlowHost Affiliate Program | Read our Blog | Follow us on X |

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14