The Community Forums

Interact with an entire community of cPanel & WHM users!
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

How to use cPanel > Ruby on Rails area with Ruby 2 and Rails 4

Discussion in 'Workarounds and Optimization' started by cPanelTristan, Oct 17, 2014.

  1. cPanelTristan

    cPanelTristan Quality Assurance Analyst
    Staff Member

    Joined:
    Oct 2, 2010
    Messages:
    7,623
    Likes Received:
    21
    Trophy Points:
    38
    Location:
    somewhere over the rainbow
    cPanel Access Level:
    Root Administrator
    Since we've frequently had requests to allow cPanel to work with higher versions or Rails, I've created a guide that would allow some of the functionality in cPanel's Ruby on Rails area to work with Rails 4. Please keep in mind this is a customization and that questions should be directed to this forum thread.

    First, Ruby, RubyGems, Rails and Passenger would need to be installed manually. The cPanel installed copies using /scripts/installruby are older versions and the Ruby versions before 1.9 do not support Rails 4.

    [RUBY INSTALL]
    To install Ruby from source (the CentOS version is too old to use from yum), please run these commands:

    Code:
    cd /root
    wget http://cache.ruby-lang.org/pub/ruby/2.1/ruby-2.1.3.tar.gz
    tar xzf ruby-2.1.3
    cd ruby-2.1.3
    ./configure
    make && make install
    ln -s /usr/local/bin/ruby /usr/bin/ruby
    ln -s /usr/local/lib/ruby /usr/lib/ruby
    Of note, the above represents the current Ruby at the time of this writing. To obtain a newer version when it becomes available, please visit https://www.ruby-lang.org/en/downloads/

    [GEM INSTALL]
    To install RubyGems from source, please run these commands:

    Code:
    cd /root
    wget [url]http://production.cf.rubygems.org/rubygems/rubygems-2.4.2.tgz[/url]
    tar zxvf rubygems-2.4.2.tgz
    cd rubygems-2.4.2
    ruby setup.rb
    ln -s /usr/local/bin/gem /usr/bin/gem
    Of note, the above represents the current RubyGems at the time of this writing. To obtain a newer version when it becomes available, please visit https://rubygems.org/pages/download

    [RAILS INSTALL]
    Code:
    gem install rails
    ln -s /usr/local/bin/rails /usr/bin/rails
    [PASSENGER INSTALL]
    To install Phusion Passenger for Rails applications, please use the following in command line:

    Code:
    gem install passenger
    yum -y install libcurl-devel
    passenger-install-apache2-module
    Add the following to /usr/local/apache/conf/includes/pre_main_global.conf file:

    Code:
    LoadModule passenger_module /usr/local/lib/ruby/gems/2.1.0/gems/passenger-4.0.53/buildout/apache2/mod_passenger.so
    <IfModule mod_passenger.c>
         PassengerRoot /usr/local/lib/ruby/gems/2.1.0/gems/passenger-4.0.53
         PassengerDefaultRuby /usr/local/bin/ruby
    </IfModule>
    Restart Apache:

    Code:
    /etc/init.d/httpd restart
    [NODEJS INSTALL]
    There are several methods to install Nodejs. I elected to use source as only the EPEL repo for CentOS has this available and other methods require git or nave. As such, to install Nodejs from source, please run these commands:

    Code:
    cd /usr/local/src
    wget http://nodejs.org/dist/node-latest.tar.gz
    tar zxvf node-latest.tar.gz
    cd node-v*
    ./configure
    make && make install
    [ADDITIONAL REQUIRED GEMS]
    There are a few other required gems for Rails to function properly for the purpose of this guide. Please install the following gems:

    Code:
    gem install spring
    yum -y install sqlite sqlite-devel
    gem install sqlite3
    gem install uglifier
    gem install turbolinks
    [RoR.pm REVISION]
    For cPanel's Ruby on Rails area to allow Rails 4 applications to be installed, please follow these instructions:

    Code:
    cp /usr/local/cpanel/Cpanel/RoR.pm /usr/local/cpanel/Cpanel/RoR.pm.bak
    sed -i 's/2.3.18/4.1.6/g' /usr/local/cpanel/Cpanel/RoR.pm
    replace "'--force', '.'" "'new', '.', '--force'" -- /usr/local/cpanel/Cpanel/RoR.pm
    To ensure the /usr/local/cpanel/Cpanel/RoR.pm file remains revised, please add the following script:

    Code:
    touch /scripts/postupcp
    chmod +x /scripts/postupcp
    Place these contents into the /scripts/postupcp file:

    Code:
    #!bin/bash
    sed -i 's/2.3.18/4.1.6/g' /usr/local/cpanel/Cpanel/RoR.pm
    replace "'--force', '.'" "'new', '.', '--force'" -- /usr/local/cpanel/Cpanel/RoR.pm
    Save the file.

    [APP INSTALL]
    cPanel > Ruby on Rails area, create the application

    [ADDING TEST CONTENTS TO APP]
    To add contents to the application for testing, run the following:

    Code:
    cd /home/$USER/rails_apps/appname
    rails generate scaffold person name:string password:string email:string age:integer
    rake db:create:all
    rake db:migrate
    cd db
    cp development.sqlite3 production.sqlite3
    chmod 666 /home/$USER/rails_apps/appname/db/production.sqlite3
    echo "RailsBaseURI /hello" >> /home/$USER/rails_apps/appname/public/.htaccess
    chown -R $USER:$USER /home/$USER/rails_apps/appname/public
    ln -s /home/$USER/rails_apps/appname/public /home/$USER/public_html/appname
    Above, please replace $USER with the cPanel username, and please replace appname with the application name used.

    [SETTING SECRET FOR config/secrets.yml FILE]
    If you've chosen a production environment for the application, Passenger will show this error in /usr/local/apache/logs/error_log if you haven't set up a secret for your application:

    Exception RuntimeError in Rack application object (Missing `secret_key_base` for 'production' environment, set this value in `config/secrets.yml`)

    To fix this, cd to your application and then run this command:

    Code:
    cd /home/$USER/rails_apps/appname
    rake secret
    As before, $USER is the cPanel username and appname would be your application name. After running "rake secret", it should output a string. Use the string provided to change this line for production:

    Code:
    secret_key_base: <%= ENV["SECRET_KEY_BASE"] %>
    To this:

    Code:
    secret_key_base: KEYHERE
    Here is an example of how it would look afterward:

    Code:
    secret_key_base: 75f1b221da444282479c27993e6bc7146b50eec8571239e0f06b4a925b3ae23e7c38130695b5328ec2b9485e06c6a2d10b781edb9ade794d19b4a8f72ee3e0bc
    Of note, development doesn't need this to be done if you had selected that as the environment.

    As a final note, the above only allows using cPanel's Ruby on Rails area to create the application. The rewrite area will not work as it uses mongrel, while mongrel will not support Rails 4. This is why Passenger is installed and used in this guide, because it does support Apache configuration with Ruby on Rails applications.

    If you have any questions, please let me know here. I plan to try to see if I can further modify the Ruby on Rails area in cPanel with code changes to remove mongrel components and add the symlink that passenger would need instead (or a working rewrite to the path).
     
  2. serverhelp247

    serverhelp247 Member

    Joined:
    Oct 17, 2014
    Messages:
    9
    Likes Received:
    0
    Trophy Points:
    1
    cPanel Access Level:
    Root Administrator
    Thanks Tristan.

    We will give it a try.
     
  3. ylluminate

    ylluminate Member

    Joined:
    Apr 12, 2013
    Messages:
    13
    Likes Received:
    1
    Trophy Points:
    1
    cPanel Access Level:
    Root Administrator
    I do have a question, but want to preface this that I'm really appreciate that you're giving some attention to this. Rails on cPanel is so very critical.

    What do you suggest for various applications with different ruby version and gemset needs? I was considering adapting your steps with RVM, but should we define a different ruby gemset environment per app in apache vhost config(s)? Or what method would allow us fine grained control over different ruby version and gemset needs per app in this scenario?

    Another important thing to note, and this is very good news, is that the Phusion Passenger guys are going to be delivering a surprise next month regarding bringing Passenger speed levels up to par or beyond that of TorqueBox, Puma, et al from what they recently noted in the mailing list.
     
  4. ylluminate

    ylluminate Member

    Joined:
    Apr 12, 2013
    Messages:
    13
    Likes Received:
    1
    Trophy Points:
    1
    cPanel Access Level:
    Root Administrator
    Well this is extremely exciting to see that Raptor turned to being Passenger 5. I guess we finally know what the cPanel team will be integrating for Ruby, Python and NodeJS / Meteor serving now! Working *extremely* well, but will be thrilled once we see this integrated into cPanel / WHM EasyApache install.
     
  5. steliosd

    steliosd Active Member

    Joined:
    Nov 25, 2013
    Messages:
    27
    Likes Received:
    0
    Trophy Points:
    1
    cPanel Access Level:
    Root Administrator
    Has anybody tried to create a ruby on rails application in a subdomain?
    Lets say that in the domain www.mywebsite.com I have a drupal installation and I want to create a subdomain for example ruby.mywebsite.com.
    Ruby works fine in the primary domain but when hosted in the subdomain it does not.Has anybody tried this?
     
  6. cPanelMichael

    cPanelMichael Forums Analyst
    Staff Member

    Joined:
    Apr 11, 2011
    Messages:
    30,762
    Likes Received:
    662
    Trophy Points:
    113
    cPanel Access Level:
    Root Administrator
    Do you notice any particular error messages, and could you let us know the specific method you used to create the app?

    Thank you.
     
  7. steliosd

    steliosd Active Member

    Joined:
    Nov 25, 2013
    Messages:
    27
    Likes Received:
    0
    Trophy Points:
    1
    cPanel Access Level:
    Root Administrator
    I followed this guide to install Rails and Passenger.
    When I go to myapp.mydomain.com I get the following rails page:

    "The page you were looking for doesn't exist.
    You may have mistyped the address or the page may have moved.
    If you are the application owner check the logs for more information."

    I don't see any errors in httpd error logs.

    Here is the relevant part from httpd.conf:

    Code:
        ServerName myapp.mydomain.gr
        ServerAlias www.myapp.mydomain.gr
        DocumentRoot /home/myuser/public_html/myapp/public
        ServerAdmin webmaster@myapp.masterpro.gr
        UseCanonicalName Off
    
        ## User masterpro # Needed for Cpanel::ApacheConf
        UserDir disabled
        UserDir enabled masterpro
    
        # Enable backwards compatible Server Side Include expression parser for Apache versions >= 2.4.
        # To selectively use the newer Apache 2.4 expression parser, disable SSILegacyExprParser in
        # the user's .htaccess file.  For more information, please read:
        #    http://httpd.apache.org/docs/2.4/mod/mod_include.html#ssilegacyexprparser
        <IfModule mod_include.c>
            <Directory "/home/myuser/public_html/myapp/public">
                SSILegacyExprParser On
            </Directory>
        </IfModule>
    
    Code:
    LoadModule passenger_module /home/myuser/.rvm/gems/ruby-2.0.0-p598/gems/passenger-4.0.56/buildout/apache2/mod_passenger.so
    <IfModule mod_passenger.c>
    PassengerRoot /home/myuser/.rvm/gems/ruby-2.0.0-p598/gems/passenger-4.0.56
    PassengerDefaultRuby /home/myuser/.rvm/gems/ruby-2.0.0-p598/wrappers/ruby
    </IfModule>
    
     
    #7 steliosd, Jan 9, 2015
    Last edited: Jan 9, 2015
  8. steliosd

    steliosd Active Member

    Joined:
    Nov 25, 2013
    Messages:
    27
    Likes Received:
    0
    Trophy Points:
    1
    cPanel Access Level:
    Root Administrator
    I have completed successfully every step but when I go to cpanel and try to install a new app, I get the following error message:

    "An unknown error was encountered when creating your rails application."

    Should I restart the server after finishing with RoR.pm REVISION?
    Any suggestions?
     
  9. kansy

    kansy Member

    Joined:
    Mar 16, 2009
    Messages:
    5
    Likes Received:
    0
    Trophy Points:
    1
    Hey, I have the same error. I've restarted httpd & rvm but did not solve the issue. Did you manage to solve it?

    Thanks
     
  10. bhadazz

    bhadazz Registered

    Joined:
    Dec 13, 2014
    Messages:
    4
    Likes Received:
    0
    Trophy Points:
    1
    cPanel Access Level:
    Root Administrator
    Hi, thanks for posting these instructions, they've been a huge help getting a current version of ruby and rails installed on my system!

    I'm having the same issue a couple others are having when trying to create a rails app from within the cPanel admin. At first I thought it was a permissions issue, so I tried manually creating the folder via SSH, but that time cPanel just gave a different message saying the app location was already in use. Any idea what I should check next?

    Thanks in advance.
     
  11. ylluminate

    ylluminate Member

    Joined:
    Apr 12, 2013
    Messages:
    13
    Likes Received:
    1
    Trophy Points:
    1
    cPanel Access Level:
    Root Administrator
    We've had Passenger and now Passenger 5 (Raptor) running for the last few months like a dream with cPanel. Would sure be nice to integrate it into the EasyApache process so that we can keep it up-to-date and somehow integrate RVM, but for now we've got several apps running great here.

    If anyone has some specific problems presently, let me know your specific questions and I'll try to help resolve them.
     
  12. DexPex

    DexPex Registered

    Joined:
    Mar 16, 2010
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    1
    Hi,

    I'm glad that can be regularly used in cpanel. I followed the instructions but at the end I got my cpanel account level message after trying to add Ruby on Rails Application

    Rails version 2.3.18 is installed. However, version 4.2.0 is required. Please contact your web hosting provider to have Rails updated.

    here are the versions:
    root@server [/]# ruby -v
    ruby 2.2.0p0 (2014-12-25 revision 49005) [x86_64-linux]
    root@server [/]# gem -v
    2.4.5
    root@server [/]# rails -v
    Rails 4.2.0
    root@server [/]#


    it seems that old version ROR ghost is still in cpanel.

    any hint to solve the problem? Thanks.
     
  13. kemal

    kemal Registered

    Joined:
    May 1, 2015
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    1
    Location:
    Turkey
    cPanel Access Level:
    Root Administrator
  14. Gur50

    Gur50 Member

    Joined:
    Jul 25, 2014
    Messages:
    13
    Likes Received:
    1
    Trophy Points:
    3
    cPanel Access Level:
    Root Administrator
    Hi Tristan firstly thank you for this guide.

    I did exactly what you have wrote above.

    How do I run application with passenger? should I add vhost config?
     
    #14 Gur50, May 17, 2015
    Last edited: May 17, 2015
  15. Gur50

    Gur50 Member

    Joined:
    Jul 25, 2014
    Messages:
    13
    Likes Received:
    1
    Trophy Points:
    3
    cPanel Access Level:
    Root Administrator
    Edit:

    Somehow Passenger didn't recognize my application ( on install i was also have choose passenger for node.js ).

    I had Postgresql connection issue, that was failed to start rails application. (Now I can understand why you wrote install postgresql if you are familiar ; ) )

    I have added those lines as extra vhost config for include


    Code:
    DocumentRoot /home/username/rails_apps/railsapp/public
        <Directory /home/username/rails_apps/railsapp/public>
            Allow from all
            Options -MultiViews
            # Uncomment this if you're on Apache >= 2.4:
            Require all granted
        </Directory>
    PassengerAppType rack
    PassengerAppRoot /home/username/rails_apps/railsapp
    Resource 1 : https://documentation.cpanel.net/display/EA/Modify+Virtualhost+Containers+With+Include+Files

    Resource 2 : https://www.phusionpassenger.com/documentation/Users guide Apache.html

    So far I have started to my application thanks to GOD.

    You should symbolic links static assets in "public" directory to "public_html" root, if you are going to different setup please look to passenger apache guide, it shows how to deploy on a "3.3. Deploying to a sub URI".

    About cPanel integration, if devs inspect passenger 5 apache guide, probably they can add Rails 4+ and Ruby 2+ support without much problem.
     
Loading...

Share This Page