Phusion Passenger is an application server which can be integrated into web server like Apache and Nginx 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 on Rails application with Nginx on Linux systems like CentOS 7/6 and Fedora 27/26. 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, use 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 Nginx 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 on your system using the following command. Also, install or update Nginx on your system.
$ sudo yum-config-manager --enable cr && sudo yum install -y nginx passenger
Step 3 – Enable Nginx Passenger Module
At this time you have installed Passenger and Apache server on your system. Now execute below command to install the passenger module for Apache. This command will show you the guided installation and tell you for any missing dependencies to install.
$ vim /etc/nginx/conf.d/passenger.conf
passenger_root /usr/share/ruby/vendor_ruby/phusion_passenger/locations.ini; passenger_ruby /usr/local/rvm/rubies/ruby-2.4.2/bin/ruby; passenger_instance_registry_dir /var/run/passenger-instreg;
The default passenger_ruby will be set up for the /usr/bin/ruby. I have changed the binary path to our custom installed Ruby version using RVM.
Step 4 – Configure Nginx VirtualHost
Let’s configure the VirtualHost in Nginx configuration file with the domain name. The example virtual host configuration will look like below.
server { listen 80 default_server; server_name example.com www.example.com; root /var/www/html/public; passenger_enabled on; }
Step 5 – Restart Nginx Service
After adding above lines in Apache configuration, restart Apache service using the following command.
$ sudo systemctl restart nginx.service
1 Comment
Hi, my app was working for quite some time until recently, it gave me a 500 error with:
Cannot stat ‘/home/profile/public_html/current/passenger_wsgi.py’: Permission denied (errno=13);
Any ideas of what could be causing it?