Canadian Web Hosting Blog and News
31Jan/084

Installing Ruby on Rails in Cpanel

cPanel 11 Stage 2 (currently in the most recent RELEASE build) have RoR functionality, including Rails and Gems options on cpanel.

Note: For RoR, Apache must have mod_proxy support.

How To Install Ruby on a cpanel Server

/scripts/installruby

How TO Install And Setup Gems

Ruby Gems are collections of functions that allow you to perform tasks in Ruby. You will need to install a Gem before you can use it inside a Ruby program.

Note: Current cpanel version has some bugs or issue with Gem Setup. We may sometimes need to configure Gems and Rails from command line.

Steps:

Install RubyGems:
----------------

cd /usr/local/src
wget http://rubyforge.org/frs/download.php/5207/rubygems-0.8.11.tgz
tar xvzf rubygems-0.8.11.tgz
cd rubygems-0.8.11
ruby setup.rb all

This step involves execution of `ruby setup.rb` with arguments `config / setup / install` all together

gem query --local
OR
gem q -L

Listing all installed gems

Install Rails:
--------------

gem install rails OR # (Enter Y for all dependencies)
gem install rails --include-dependencies

Note: maximum memory a cPanel process can be used must be set to a value greater than 128M(WHM > Server Configuration -> Tweak Settings)

Location of Your Ruby Gem on Application(s)

Path: /home/username/ruby/gems

Using Your Ruby Gem(s)

You will need to add /home/username/ruby/gems to the include path. You can do this by adding the following code to your script:

$:.push("/home/username/ruby/gems")

Start And Stop Ruby Application

Once the setup is completed. You can start/stop the application using the Action button on cpanel

Set up a Redirection

The default port appears to be 12001, so the actual URL is: http://domain.com:12001/ ..which loads the app running at: /home/domain/path/to/rails/app/appname http://domain.com/Applnname to http://domain.com:12001/Applnname

You can set up this redirection using a .htaccess file inside the "Applnname" directory.

Here the complete installation process :

a) /scripts/installruby (unfortunately it is currently not perfect, no idea why)

b) gem install rails

c) gem install mongrel

if fastthread isn't installed (normally you will be asked for fastthread during mongrel installation)

d) gem install fastthread

Don't forget to open firewall ports 3000 and 12001

 

Kevin Liang
CTO / SEO Guru
Canadian Web Hosting
http://www.canadianwebhosting.com/

Related Posts:

  • No Related Posts
Comments (4) Trackbacks (0)
  1. Could you explain what the following refers to? Specifically, which script do you mean?

    You will need to add /home/username/ruby/gems to the include path. You can do this by adding the following code to your script:

    $:.push(“/home/username/ruby/gems”)

  2. Yeh, I’m stuck with that as well.
    Ant

  3. 1) By default, on cPanel servers, the path to local ruby gems will
    be ‘/home/cpanel_username/.gem/ruby/1.8′ or ‘/home/cpanel_username/ruby/gems’

    Each user can SSH to their account and run the command ‘gem environment’ to
    find out the ‘GEM PATHS’

    Eg:
    ——————
    user@domain.ca [~]# gem environment
    RubyGems Environment:
    – RUBYGEMS VERSION: 1.3.5
    – RUBY VERSION: 1.8.7 (2008-06-20 patchlevel 22) [i686-linux]
    – INSTALLATION DIRECTORY: /usr/lib/ruby/gems/1.8
    – RUBY EXECUTABLE: /usr/bin/ruby
    – EXECUTABLE DIRECTORY: /usr/bin
    – RUBYGEMS PLATFORMS:
    – ruby
    – x86-linux
    – GEM PATHS:
    – /usr/lib/ruby/gems/1.8
    – /home/cpanel_username/.gem/ruby/1.8
    – GEM CONFIGURATION:
    – :update_sources => true
    – :verbose => true
    – :benchmark => false
    – :backtrace => false
    – :bulk_threshold => 1000
    – REMOTE SOURCES:
    http://gems.rubyforge.org/
    ——————

    Here the gem path is already set to ‘/usr/lib/ruby/gems/1.8′ (servers default
    location) and ‘/home/cpanel_username/.gem/ruby/1.8′ (local location).

    2) If the local gem path is not loaded (non cPanel servers), customer can set
    them by following the steps below (this shouldn’t be needed on cPanel
    servers) :

    mkdir gems (in home dir)
    vi .gems (in home dir)
    add the lines in the .gems file
    gemhome: /home/username/gems
    gempath:
    - /home/username/gems
    - /usr/lib/ruby/gems/1.8

    They can also add GEM_PATH and GEM_HOME in .bash_profile

    —–
    export GEM_PATH=/home/username/gems:/usr/lib/ruby/gems/1.8
    export GEM_HOME=/home/username/gems
    —–

    3) Regarding mentioning the local gem path in ruby application scripts:

    Each ruby application will have a ‘environment.rb’ file in the config
    directory.

    vi /path/to/your/railsapp/config/environment.rb

    Add:

    ENV['GEM_PATH'] = ‘ /home/cpanel_username/.gem/ruby/1.8:/usr/lib/ruby/gems/1.8′

  4. Hi,

    I have added the gempath to .gemrc file under user home directory and it worked !!!

    gempath:
    - /home/username/gems
    - /usr/lib/ruby/gems/1.8


Leave a comment

(required)

No trackbacks yet.