Select Page

Bobcares Blog

Tried and tested solutions for your servers, from our outsourced support diaries.

Using Phusion Passenger (a.k.a mod_rails) On cPanel Server

Phusion Passenger (mod_rails or mod_rack ) makes execution of Ruby web applications more easier on Apache webserver. It requires no maintenance from our part and minimal port management. It was designed keeping in mind performance, stability and security.

Here I am explaining more about deploying this module on Linux servers using cPanel as the control panel.

Currently in cPanel, by default, the Ruby On Rails(RoR) applications are using Mongrel webserver. By Phusion Passenger, we can use Apache itself for RoR applications, instead of redirecting the application to Mongrel.


We can install Phusion Passenger using different methods. An Easy way is to use gem to install Phusion Passenger in two simple steps. Make sure that RoR is already installed on your cPanel server using ‘/scripts/installruby‘.

Step 1: #gem install passenger
Step 2: #passenger-install-apache2-module

In the second step, while installing ‘passenger-install-apache2-module’, I ran into two errors. The errors and corresponding solutions are given below.

Error 1: Apache 2 development headers were not detected by the script.

Checking for required software...

 * GNU C++ compiler... found at /usr/bin/g++
 * Ruby development headers... found
 * OpenSSL support for Ruby... found
 * RubyGems... found
 * Rake... found at /usr/bin/rake
 * Apache 2... found at /usr/local/apache/bin/httpd
 * Apache 2 development headers... missing..(some error here)

Solution: Here the script is checking for apxs installation path. On a cPanel server, the default path is ‘/usr/local/apache/bin/apxs‘. But the script was looking for ‘/usr/sbin/apxs’. To solve this, I created a symbolic link from ‘/usr/sbin/apxs‘ to ‘/usr/local/apache/bin/apxs‘.

Error 2: Another error that came up was:

/usr/local/apache/include/apr_file_info.h:200: error: 'apr_ino_t' does not name a type ..."

Solution: There were two installation of apr on the server. One by default and one by cPanel. The passenger script was taking binary path from one installation and include files from other. I moved the default installation on the server to a backup folder and created a symbolic link from default installation’s include directory to apr include directory of cPanel. The command for this is given below:

#ln -s /usr/local/apache/include/ /usr/include/apr-1

Loading Modules

After completing the ‘passenger-install-apache2-module’ step successfully, add the corresponding Modules to Apache configuration file.

LoadModule passenger_module /usr/lib/ruby/gems/1.8/gems/passenger-
   PassengerRoot /usr/lib/ruby/gems/1.8/gems/passenger-2.0.2
   PassengerRuby /usr/bin/ruby

Save and restart Apache.

#/usr/local/cpanel/bin/apache_conf_distiller --update
#/etc/init.d/httpd restart.

Deploying RoR application:

Suppose, we have a RoR application in “/home/username/testapp”. Follow the steps given below to redirect the main domain to this application.

Step 1: By default the Document root of this domain will be /home/username/public_html/. Create a symbolic link from /home/username/public_html/ to the RoR application’s public directory, /home/username/testapp/public/.

-bash-3.2# ln -s  /home/username/testapp/public/ /home/username/public_html

Step 2: Then add the following rule in the virtual host entry of the domain.

RailsBaseURI /

Note : If you want to redirect a subdirectory under public_html like http://domainname/rails to the RoR’s application, change the symbolic link accordingly and specify the rule in the domain’s virtualhost entry as:

RailsBaseURI /subdirectory_name

It is not recommended to edit the virtual host entry directly. You can add this rule in the include file mentioned in the virtual host entry of the domain.

Include "/usr/local/apache/conf/userdata/std/2/username/domain_name/*.conf"

By default these include files will be commented in the configuration file. We have to manually create directories corresponding to this include file.

Directories up-to /usr/local/apache/conf/ were already there in the server. I created new sub-directories from ‘userdata’ to ‘domain_name’. Under the directory /usr/local/apache/conf/userdata/std/2/username/domain_name/, you can create any file with .conf extension. I created the file rails.conf to add the “RailsBaseURI” rule.

-bash-3.2# ll /usr/local/apache/conf/userdata/std/2/username/domain_name/
total 4
-rw-r--r-- 1 root root 15 Jul 31 04:05 rails.conf

Step 3: After that, execute the below command,

#/scripts/ensure_vhost_includes --user=username  (Use cpanel username of that domain)

Step 4: You can restart the RoR application by restarting Apache or using the command,

#touch /path_to_application/tmp/restart.txt

In this case,

#touch /home//username/testapp/tmp/restart.txt

The domain will now work fine using this new mod_rails installation. 🙂 Make sure that you are not starting or restarting this application from cPanel >> Ruby On Rails option. It will switch to Mongrel webserver.

You can check Apache error log file itself for errors.


Although cPanel is not using this module (mod_rails) with Easyapache script and in their Ruby Ob Rails interface. By following this method, we can use this module on a cPanel server with much ease.

Phusion Passenger conflicts with some Apache modules like mod_rewrite and mod_alias. They may be installed together with mod_passenger and used outside virtual hosts that contain a Rails application. Phusion Passenger recommend not to use their features inside virtual hosts that contain a Rails application. Rewrite rules are mainly used to accelerate caching of pages. Phusion Passenger supports page caching without mod_rewrite. So there is no need to worry about this.

Reference :

Articles by Anusha M.K

About the author
Anusha M.K has been working with Bobcares for more than one and half years. She specializes on Linux and Windows server administration using variety of control panels. She is an expert in Ruby On Rails technology especially its configurations and deployment in Linux servers.



  1. Firstly make sure you add the generated code to :


    and not


    or otherwise cPanel will overwrite it when it does updates.

    Another way or running the command to install the passenger Apache2 Module without creating a link is :

    APXS2=/usr/local/apache/bin/apxs PATH=$PATH:/usr/local/apache/bin passenger-install-apache2-module

  2. Hi

    I get the following error after the script successfully ran:

    /usr/local/bin/rails /usr/local/bin/ruby : bad interpreter: No such file or directory

  3. Hi,

    If you are executing the application using any scripts in the scripts directory of rails application, make sure that rails/ruby is installed in the interpreter path defined in that file. You can see the shebang line as,

    #!/usr/bin/env ruby

    In this case, ruby should be installed in /usr/bin/ruby. Like this, check your ruby installation path.

  4. In my case, I didn’t get any error in the first part “Checking for required software…” but I get this error in the second part “Compiling and installing Apache 2 module…”:

    g++ ext/common/ApplicationPoolServerExecutable.cpp -o ext/apache2/ApplicationPoolServerExecutable -Iext -Iext/common -fPIC -DLINUX=2 -D_REENTRANT -D_GNU_SOURCE -I/usr/local/apache/include -I/usr/local/apache/include -I/usr/local/apache/include -D_REENTRANT -I/usr/local/include -Wall -g -DPASSENGER_DEBUG -DBOOST_DISABLE_ASSERTS ext/apache2/libpassenger_common.a ext/apache2/libboost_oxt.a -fPIC -L/usr/local/apache/lib -lapr-0 -L/usr/local/apache/lib -laprutil-0 -lpthread
    /usr/local/apache/lib/ undefined reference to `XML_ParserCreate’
    /usr/local/apache/lib/ undefined reference to `XML_GetErrorCode’
    /usr/local/apache/lib/ undefined reference to `XML_SetUserData’
    /usr/local/apache/lib/ undefined reference to `XML_ErrorString’
    /usr/local/apache/lib/ undefined reference to `XML_ParserFree’
    /usr/local/apache/lib/ undefined reference to `XML_SetElementHandler’
    /usr/local/apache/lib/ undefined reference to `XML_Parse’
    /usr/local/apache/lib/ undefined reference to `XML_SetCharacterDataHandler’
    collect2: ld returned 1 exit status
    rake aborted!
    Command failed with status (1): [g++ ext/common/ApplicationPoolServerExecut…]
    /usr/lib/ruby/gems/1.8/gems/passenger-2.2.1/Rakefile:211:in `define_common_library_task’
    (See full trace by running task with –trace)

    Any ideas?

  5. gdelfino: I’m getting the same. I’ll try to update if I get past it.



About Bobcares

Bobcares Bobcares is a server management company that helps businesses deliver uninterrupted and secure online services.
Our engineers manage close to 52,500 servers that include virtualized servers, cloud infrastructure, physical server clusters, and more.