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:
Now we can install the passenger gem:
Next, compile the apache2 module
The 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.
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:
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:
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:
To make sure those files load, run this:
We need to make sure cPanel records the changes we have for when it rebuilds those files, so run the following two commands:
We can now restart apache:
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:
To restart that application, you just need to touch the restart.txt file:
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.
PS:
I just modified few lines from this article after i installed passenger on my cpanel server.