Although cPanel has built in support for running Ruby or Rails apps, it uses Mongrel as the server and doesn’t allow more than one instance per user. That makes it pretty useless for any application that gets even a moderate amount of traffic. Instead we can install Phusion Passenger (a.k.a mod_rails), which in my opinion is a much nicer solution anyway.
First we need to make sure Ruby is installed via a cpanel script:
sudo /script/installruby
Now we can install the passenger gem:
sudo gem install passenger
Next, compile the apache2 module
sudo passenger-install-apache2-moduleThe installer may tell you that the the Apache development headers are needed and will suggest ‘yum install httpd-devel’. Since cPanel compiles it’s own version of apache, yum is configured to ignore that package. That is OK, because the program we need is already installed, we just have to tell Passenger where to find it.
APXS2=/usr/local/apache/bin/apxs PATH=$PATH:/usr/local/apache/bin passenger-install-apache2-module
Everything should go OK this time, and the installer will give you a few lines to add to your apache config file. It’s best practice with cPanel not to put these in your main httpd.conf, but rather the pre_main_global.conf:
vi /usr/local/apache/conf/includes/pre_main_global.conf LoadModule passenger_module /usr/lib/ruby/gems/1.8/gems/passenger-X.X.X/ext/apache2/mod_passenger.so PassengerRoot /usr/lib/ruby/gems/1.8/gems/passenger-X.X.X PassengerRuby /usr/bin/ruby
Now we need to setup passenger to run on a per virtual host basis. Open up the httpd.conf file and find the virtual host you want to run a Rails app and add this line:
Include "/usr/local/apache/conf/userdata/std/2/username/domain_name/*.conf"Replace username with the username of the account.
Now we need to create the directory we just specified, and also create a configuration file letting passenger know it should load for this host:
mkdir -p /usr/local/apache/conf/userdata/std/2/username/domain_name/ vi /usr/local/apache/conf/userdata/std/2/username/domain_name/rails.conf RailsBaseURI /
To make sure those files load, run this:
/scripts/ensure_vhost_includes --user=username
We need to make sure cPanel records the changes we have for when it rebuilds those files, so run the following two commands:
/usr/local/cpanel/bin/apache_conf_distiller --update /usr/local/cpanel/bin/build_apache_conf
We can now restart apache:
/etc/init.d/httpd restart
Since by default the Apache Document Root for each host is /home/username/public_html, you will probably need to symlink that to your applications public directory:
ln -s /home/username/railsapp/public /home/username/public_html
To restart that application, you just need to touch the restart.txt file:
touch /home/username/railsapp/tmp/restart.txt
And there you have it, a working high performance rail application server on cPanel! For more information on tuning the Passenger configuration, read the complete docs.

September 29th, 2009 at 10:54 am
[...] for most linux distros. It assumes you already have Passenger and Munin successfully setup. See my previous article on getting Phusion Passenger setup if you have not [...]
November 28th, 2009 at 7:09 pm
[...] Jetpack Flight Log » Install Phusion Passenger (a.k.a. mod_rails) on cPanel Server [...]
January 9th, 2010 at 4:49 pm
[...] I just modified few lines from this article after i installed passenger on my cpanel server. original source of this article is: http://jetpackweb.com/blog/2009/07/21/install-phusion-passenger-a-k-a-mod_rails-on-cpanel-server/ [...]
March 19th, 2010 at 2:28 pm
Thanks for the tutorial was very helpful.
But me only worked when I changed the DocumentRoot in Apache’s httpd.conf file to the directory that is the application Rais.
Only with “ln-s /home/username/railsapp/public/home/username/public_html” simply does not work, returns the error:
Can not start Ruby on Rails application
The directory “/home/username” does not appear to be a valid Ruby on Rails application root.
You know what would be wrong to work without having to change the setting that made the cPanel?
Thank you!
May 4th, 2010 at 10:10 pm
It is also easy to backup and transfer all your websites from one server to another server if you have cPanel installed,”,