From time-to-time we’ll often get requests from customers on how to run Ruby apps on cPanel. Over the years we’ve seen a steep decline in such requests, but there are certainly still instances where it’s much needed.
Despite cPanel adding their Application Manager to run Ruby on Rails with Phusion Passenger, I’ve still found it to be a pain in the neck. The native version of Ruby that ships in Easy Apache 4 is quite dated and I was unable to successfully upgrade it (if someone knows a way feel free to share in the comments below).
After a lot of trial and error, I found the best way to run Ruby on a cPanel server is to install Ruby on Rails directly as well as Phusion Passenger.
Note: The following tutorial is specifically for CentOS 7 servers running cPanel/WHM. It would prob be best to run Ruby on a standard CentOS 7 without cPanel, which you can do with our FlexVPS, but sometimes that’s not ideal for customers who need a control panel.
- An active VPS or Cloud Dedicated server running cPanel/WHM
- At least 2GB of RAM
- Full root access (available on all VPS and Cloud Dedicated)
- Apache 2.4 installed with Easy Apache 4
- Confirm with the following command:
[[email protected] ~]# httpd -v Server version: Apache/2.4.41 (cPanel) Server built: Jan 28 2020 19:40:24
To get started, you want to install the latest version of Ruby.
For me, this was the root of my initial problem since the version of Ruby in the EA4 was quite dated and using yum also installs an old version shipped with CentOS.
As of this writing, the latest stable version is Ruby 2.7.0, but you can check their website to make sure.
To install, you’ll want to get the Ruby Version Manager (RVM). Start with the following commands via ssh as your root user:
[[email protected] ~]# gpg2 --keyserver hkp://keys.gnupg.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 [[email protected]host2 ~]# curl -L get.rvm.io | bash -s stable [[email protected] ~]# source /etc/profile.d/rvm.sh [[email protected] ~]# rvm requirements
Make sure each of these completes successfully and resolve any errors before proceeding.
You can then install the latest version of Ruby:
[[email protected] ~]# rvm install 2.7.0
You’ll then want to set that as default to avoid conflicts when you start deploying applications:
[[email protected] ~]# rvm use 2.7.0 --default
Finally, install Rails:
[[email protected] ~]# gem install rails
Install Phusion Passenger
Phusion Passenger is a feature-rich web app server that integrates very nicely with Apache (and Nginx) which will allows your Ruby apps to run with ease.
Install with the following commands:
[[email protected] ~]# gem install passenger
[[email protected] ~]# yum -y install curl-devel sqlite-devel
[[email protected] ~]# passenger-install-apache2-module
Once again, if you get any errors running these, you’ll want to resolve them. This specifically is where RAM comes into play, to be safe, I always like to have at least 4GB just to be on the safe side.
When you complete the final command (installing the Passenger Apache Module) it’ll provide you a line of code you’ll need to copy for the following step. It’ll look something like this:
LoadModule passenger_module /usr/local/rvm/gems/ruby-2.3.8/gems/passenger-6.0.4/buildout/apache2/mod_passenger.so
< IfModule mod_passenger.c>
Make sure to copy the output from your terminal and not my example above as I’ve had to modify it a bit to get it to display in this post :).
Include Passenger Into Apache Config
In order for Apache to serve your Ruby apps, you’ll need to configure the location of Passenger/Ruby.
cPanel servers require you to place these in include files so they’re not overwritten during their EA updates.
Simply create a new file with the output received above:
[[email protected] ~]# nano /usr/local/apache/conf/passenger.conf
Save the file, then include it in /usr/local/apache/conf/includes/pre_main_global.conf
You can also use the Apache Configuration editor in Web Host Manager if you prefer:
You then have to rebuild your Apache configuration:
[[email protected] ~]# /scripts/rebuildhttpdconf
And then restart Apache:
[[email protected] ~]# service httpd restart
If you followed all of these steps correctly, you are now all set to go run Ruby apps on cPanel!
Now as a disclaimer, this method is not supported by cPanel, hence we’re unable to support it at NameHero. However if you’re like me and are ready to pull your hair out trying to run the latest version of Ruby on a cPanel server, I found this was the best way to do it, and it actually works.
Feel free to let me know if you have any questions, I’ll try my best to help!
Ryan Gray is the founder and CEO of NameHero, one of the fastest growing independent web hosts in the United States. Ryan has been working online since 1998 and has over two-decades experience in Internet Entrepreneurship.