How to use cPanel > Ruby on Rails area with Ruby 2 and Rails 4
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 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
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).
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/rubyOf note, the above represents the current Ruby at the time of this writing. To obtain a newer version when it becomes available, please visit 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
To ensure the /usr/local/cpanel/Cpanel/RoR.pm file remains revised, please add the following script:
touch /scripts/postupcp
chmod +x /scripts/postupcpPlace these contents into the /scripts/postupcp file:
#!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.pmSave 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:
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/appnameAbove, 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:
cd /home/$USER/rails_apps/appname
rake secretAs 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:
secret_key_base: <%= ENV["SECRET_KEY_BASE"> %>To this:
secret_key_base: KEYHEREHere is an example of how it would look afterward:
secret_key_base: 75f1b221da444282479c27993e6bc7146b50eec8571239e0f06b4a925b3ae23e7c38130695b5328ec2b9485e06c6a2d10b781edb9ade794d19b4a8f72ee3e0bcOf 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).
-
Thanks Tristan. We will give it a try. 0 -
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. 0 -
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. 0 -
]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.0 -
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: 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 SSILegacyExprParser On
LoadModule passenger_module /home/myuser/.rvm/gems/ruby-2.0.0-p598/gems/passenger-4.0.56/buildout/apache2/mod_passenger.so 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/ruby0 -
] [RoR.pm REVISION] For cPanel's Ruby on Rails area to allow Rails 4 applications to be installed, please follow these instructions:
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:touch /scripts/postupcp chmod +x /scripts/postupcp
Place these contents into the /scripts/postupcp file:#!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?0 -
]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? Thanks0 -
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. 0 -
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. 0 -
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. 0 -
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? 0 -
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 DocumentRoot /home/username/rails_apps/railsapp/public Allow from all Options -MultiViews # Uncomment this if you're on Apache >= 2.4: Require all granted PassengerAppType rack PassengerAppRoot /home/username/rails_apps/railsapp
Resource 1 : Resource 2 : 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.0
Please sign in to leave a comment.
Comments
14 comments