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

cPanelTristan

Quality Assurance Analyst
Staff member
Oct 2, 2010
7,607
40
248
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).
 

ylluminate

Member
Apr 12, 2013
16
2
3
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.
 

ylluminate

Member
Apr 12, 2013
16
2
3
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.
 

steliosd

Active Member
Nov 25, 2013
27
0
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?
 

cPanelMichael

Administrator
Staff member
Apr 11, 2011
47,908
2,216
463
Ruby works fine in the primary domain but when hosted in the subdomain it does not.Has anybody tried this?
Do you notice any particular error messages, and could you let us know the specific method you used to create the app?

Thank you.
 

steliosd

Active Member
Nov 25, 2013
27
0
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 [email protected]
    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>
 
Last edited:

steliosd

Active Member
Nov 25, 2013
27
0
1
cPanel Access Level
Root Administrator
[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
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?
 

kansy

Member
Mar 16, 2009
5
0
51
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?
Hey, I have the same error. I've restarted httpd & rvm but did not solve the issue. Did you manage to solve it?

Thanks
 

bhadazz

Registered
Dec 13, 2014
4
0
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.
 

ylluminate

Member
Apr 12, 2013
16
2
3
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.
 

DexPex

Registered
Mar 16, 2010
1
0
51
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:
[email protected] [/]# ruby -v
ruby 2.2.0p0 (2014-12-25 revision 49005) [x86_64-linux]
[email protected] [/]# gem -v
2.4.5
[email protected] [/]# rails -v
Rails 4.2.0
[email protected] [/]#


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

any hint to solve the problem? Thanks.
 

Gur50

Member
Jul 25, 2014
13
1
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?
 
Last edited:

Gur50

Member
Jul 25, 2014
13
1
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
https://www.phusionpassenger.com/documentation/Users%20guide%20Apache.html
Resource 2 : https://www.phusionpassenger.com/documentation/Users guide Apache.html
https://www.phusionpassenger.com/documentation/Users%20guide%20Apache.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.