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:
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:
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]
[PASSENGER INSTALL]
To install Phusion Passenger for Rails applications, please use the following in command line:
Add the following to /usr/local/apache/conf/includes/pre_main_global.conf file:
Restart Apache:
[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:
[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:
[RoR.pm REVISION]
For cPanel's Ruby on Rails area to allow Rails 4 applications to be installed, please follow these instructions:
To ensure the /usr/local/cpanel/Cpanel/RoR.pm file remains revised, please add the following script:
Place these contents into the /scripts/postupcp file:
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:
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:
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:
To this:
Here is an example of how it would look afterward:
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).
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
[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
[RAILS INSTALL]
Code:
gem install rails
ln -s /usr/local/bin/rails /usr/bin/rails
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
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>
Code:
/etc/init.d/httpd restart
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
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
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
Code:
touch /scripts/postupcp
chmod +x /scripts/postupcp
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
[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
[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
Code:
secret_key_base: <%= ENV["SECRET_KEY_BASE"] %>
Code:
secret_key_base: KEYHERE
Code:
secret_key_base: 75f1b221da444282479c27993e6bc7146b50eec8571239e0f06b4a925b3ae23e7c38130695b5328ec2b9485e06c6a2d10b781edb9ade794d19b4a8f72ee3e0bc
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).