Using Passenger with cPanel on CentOS 7

Phusion Passenger is a web application server that can run Ruby, Node.js, and Python applications on your webserver. It integrates with both Apache and Nginx to serve content to your visitors. Historically, this application was difficult to integrate with cPanel servers, which would combine the power of Ruby applications with the ease of management that cPanel provides, but recent advancements make setting up your Passenger module very simple. This easy walkthrough will show you how to add Passenger, Apache mod_passenger, and the supporting Ruby installation to cPanel.

Using Apache and Phusion Passenger to host Ruby sites on your cPanel server

For this installation, we’ll be using a CentOS 7 VPS with cPanel, and we are connected via SSH.

  1. First, we must make sure that we are using EasyApache 4, which was made available in WHM 58. If you aren’t running WHM 58 or greater, we recommend upgrading to the latest available ‘Release’ tier version to ensure you are getting the most out of your webserver.
  2. From the server’s command line as root, you can check for the existence of the blank file ‘/etc/cpanel/ea4/is_ea4’ to see if your system is running EasyApache 4. If the file isn’t there, you’ll need to upgrade from EasyApache 3.
    ls /etc/cpanel/ea4/is_ea4
  3. Once you are sure that your server is using EasyApache 4, the next step is to add the mod_passenger option into your EasyApache 4 configuration. From the command line, you can install the necessary module and its supporting packages using YUM. The command you would use is:
    yum -y update; yum -y install ea-ruby24-mod_passenger ea-ruby24-ruby-devel ea-apache24-devel
  4. There is one more item we need in order to install Ruby applications easily: bundle. Install it using ‘gem’:
    scl enable ea-ruby24 'gem install bundle'
  5. Let’s confirm that mod_passenger, the connector to Apache, was installed properly. From the command line, you would run this command:
    httpd statusYour output should say something like ‘Server Version: Apache/2.4.29 (cPanel) OpenSSL/1.0.2n mod_bwlimited/1.4 Phusion_Passenger/5.1.8’ in the first few lines, indicating that Passenger is installed and running.

    1. If you don’t have mod_status enabled, you can also check this command for any output:
      httpd -L | grep mod_passenger
  6. Let’s also make sure that Passenger itself is set up and working. Run this command to start the validator:
    scl enable ea-ruby24 'passenger-config validate-install'

That’s all! Passenger is now installed on your cPanel server.

Example: Setting up a Ruby app with Phusion Passenger

Now that we have it set up, let’s configure a simple Ruby app.

  1. First, we must upload the software for our app into a folder on the cPanel account. This folder doesn’t have to be inside of public_html. In fact, it’s more secure if its outside of public_html. I chose /home/username/rubyapp/ to upload our test files. Depending on how you manage your code, you might use FTP, SSH, or Git for this step.
  2. Next, we will need to install any gems that the Ruby app needs to work; its dependencies. This is done with the following command, run as the cPanel user hosting the app:
  3. Log into cPanel for the account for which you are setting up the Rails app, and go to the Application Manager (Home >> Software >> Application Manager). Click on ‘Add Application’. Add the details for your Ruby app here, including what domain and subfolder you wish to access the app from publicly, and the location of the installation. Usually this folder contains another folder called ‘app’, rubyapp/ in our example.
  4. Save the configuration. This creates the appropriate Passenger configuration files and starts the application.

Once you save this application configuration, cPanel will add the necessary lines into your custom apache virtualhost include to proxy calls to the Passenger module. Give it a minute to restart apache, and then head to your website to see how you did!

Be Sociable, Share!
Here's 75 % off, Launch a New VPS Today. Find out why 30,000 customers have chosen our Best-in-Class Performance & 24x7 Heroic Support