cPanel Blog

Installing mod_rails and Rails 3.0.9 on a cPanel machine

While Rails 3 and mod_rails (aka Phusion Passenger) are not yet supported with cPanel, it is possible in 30 minutes or less to install Rails 3.0.9, install mod_rails and get a working application using mod_rails in place of mongrel.

Of note, the steps I am about to provide are to be used at your own risk. cPanel > Ruby on Rails applications cannot and should not be used if you decide to follow this guide, since the current cPanel environment only supports Rails 2.3.12 rather than Rails 3.0.9. Support is being planned for Rails 3 and mod_rails in cPanel 11.34 (more details can be found at this location).

In root SSH to install the newest Rails version to replace Rails 2.3 ones, please run the following command:
gem install rails

Next, install mod_rails with these commands:
gem install passenger
passenger-install-apache2-module

After installation, edit /usr/local/apache/conf/includes/pre_main_global.conf to add the following lines:
LoadModule passenger_module /usr/lib/ruby/gems/1.8/gems/passenger-3.0.8/ext/apache2/mod_passenger.so
PassengerRoot /usr/lib/ruby/gems/1.8/gems/passenger-3.0.8
PassengerRuby /usr/bin/ruby

Please change passenger-3.0.8 above to whatever version of passenger was installed when using “gem install passenger” command. To check, you can always run the following command:
# gem list --local | grep -i passenger
passenger (3.0.8)

At that point, make a backup of httpd.conf file, distill the changes, rebuild Apache and restart Apache with these commands:
cp /usr/local/apache/conf/httpd.conf /usr/local/apache/conf/httpd.conf.bak-modrails
/usr/local/cpanel/bin/apache_conf_distiller --update
/scripts/rebuildhttpdconf
/etc/init.d/httpd restart

To test a working application, a hello world application can be generated with the following steps:
rails new /home/username/hello
cd /home/username/hello
rails generate scaffold person name:string password:string email:string age:integer
rake db:create:all
rake db:migrate

After this, create a symlink from /home/username/hello/public to /home/username/public_html/hello folder:
ln -s /home/username/hello/public /home/username/public_html/hello

Copy the development database in sqlite to the production one:
cd /home/username/hello/db
cp development.sqlite3 production.sqlite3

Chown the application files to the user:
chown -R username:username /home/username/hello

Finally, create a rewrite for the subdomain folder and restart Apache again:
echo "RailsBaseURI /hello" >> /home/username/hello/public/.htaccess
/etc/init.d/httpd restart

For an example application, one is available at the following location that was based on using the above guide: http://tristanwallace.com/hello/people

Hopefully, these instructions will help anyone who does require mod_rails and Rails 3 to function in the meantime prior to cPanel 11.34

– Posted by Tristan Wallace

cPanel

The web hosting industry's most reliable, intuitive control panel since 1997. With our first-class support and rich feature set, it's easy to see why our customers and partners make cPanel & WHM their hosting platform of choice. For more information, visit cPanel.com.