I recently had occasion to set up Passenger/mod_rails on a cPanel server. There is some varying and dated information around the web, so I thought I would share current best practice:
First you’ll need to SSH to your server and perform all the following commands as root or via sudo:
$ su
Let cPanel set up Ruby and Rails the way it wants:
$ /scripts/installruby $ /usr/local/cpanel/bin/ror_setup
Install passenger the normal way (see Passenger docs):
$ gem install passenger $ passenger-install-apache2-module
Create /usr/local/apache/conf/passenger.conf with the lines that the Passenger install script tells you to add to your Apache configuration file, e.g.:
LoadModule passenger_module /usr/lib/ruby/gems/1.8/gems/passenger-2.2.11/ext/apache2/mod_passenger.so PassengerRoot /usr/lib/ruby/gems/1.8/gems/passenger-2.2.11 PassengerRuby /usr/bin/ruby
Include the Passenger config by editing /usr/local/apache/conf/httpd.conf and, somewhere near the beginning, adding:
Include "/usr/local/apache/conf/passenger.conf"
We want to make sure cPanel preserves our edits to httpd.conf when it does updates, so we need to run:
$ /usr/local/cpanel/bin/apache_conf_distiller --update --main
Restart Apache with
$ /scripts/restartsrv_httpd
Upload your Rails app to somewhere outside of public_html (e.g. ~/rails_apps/yourapp) or use cPanel’s “Software / Services > Ruby on Rails” functions to create a new one.
Login to your domain’s cPanel and go to “Domains > Subdomains”
Create a new subdomain whose document root is path/to/yourapp/public
Make sure it’s pointing to yourapp/public
Visit your subdomain and see your app running — easy!