Phusion Passenger is an application server which can be integrated into web server like Apache web servers and allows to serve Ruby/Rails applications via the web server. It’s a good option to deploy Ruby on Rails application on productions systems. This article will help you to deploy Ruby application with Apache on CentOS, Red Hat and Fedora systems. You can use this tutorial for staging as well as production deployments.
First of all, we assume you already have Ruby installed on your system. If you do not have Ruby installed on your system, Use one of below URL to install it as per your application requirements.
Step 1 – Install Prerequisites
First of all, enable epel yum repository and update packages on your system.
$ sudo yum install -y epel-release yum-utils $ sudo yum-config-manager --enable epel $ sudo yum clean all && sudo yum update -y
Step 2 – Install Apache Passenger Module
Now install rails and passenger gem on your system. Execute below commands to install both gem command.
$ sudo yum install -y pygpgme curl $ sudo curl --fail -sSLo /etc/yum.repos.d/passenger.repo https://oss-binaries.phusionpassenger.com/yum/definitions/el-passenger.repo
Now install the passenger for the Apache on your system using the following command.
$ sudo yum-config-manager --enable cr && sudo yum install -y mod_passenge
Step 3 – Validate Apache Passenger Module
The default passenger configuration file for Apache create at /etc/httpd/conf.d/passenger.conf. You can edit this file and check the settings like below.
$ vim /etc/httpd/conf.d/passenger.conf
The default PassengerRuby option is set to /usr/bin/ruby. I have changed it to our custom ruby installed with rvm like below screenshot.
Now, validate the passenger installation and configuration with the following command.
$sudo /usr/bin/passenger-config validate-install
Step 4 – Configure Apache VirtualHost
Let’s configure the VirtualHost in Apache configuration with the domain name. The example virtual host configuration will look like below.
<VirtualHost *:80> ServerName
example.com # Path to Ruby Application's 'public' directoryDocumentRoot /path-to-your-app/public <Directory /path-to-your-app/public> Allow from all Options -MultiViews # Uncomment this if you're on Apache > 2.4: #Require all granted </Directory> </VirtualHost>
Step 5 – Restart Apache Service
After adding above lines in Apache configuration, restart Apache service using the following command.
$ sudo systemctl restart httpd.service