Ruby on Rails with Nginx on Debian 8
Updated by Elle Krout
Ruby on Rails is a rapid development web framework that allows web designers and developers to implement dynamic fully featured web applications. This guide describes the required process for deploying Ruby on Rails with Passenger and the Nginx web server on Debian 8.
This guide is written for a non-root user. Commands that require elevated privileges are prefixed with
sudo. If you’re not familiar with the
sudocommand, you can check our Users and Groups guide.
Before You Begin
To check the hostname run:
hostname hostname -f
The first command should show the short hostname, and the second should show the fully qualified domain name (FQDN).
Update the system:
sudo apt-get update && sudo apt-get upgrade
Uninstall Nginx, if currently installed on the Linode. Nginx does not support loadable modules and is contained in the Phusion Passenger package:
sudo apt-get remove nginx nginx-full nginx-light nginx-common
Install Passenger and Nginx
Install the system packages required for using Ruby, building Ruby modules, and running Rails applications:
sudo apt-get install build-essential ruby ruby-dev zlib1g-dev libruby libssl-dev libpcre3-dev libcurl4-openssl-dev rake ruby-rack rails
Additionally, the deployed application will likely have dependencies. Install these dependencies before proceeding.
Phusion hosts a repository containing the latest version of Phusion Passenger. To add this to the package manager, first install the Phusion PGP key:
sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 561F9B9CAC40B2F7
sudoor as the root user, create the file
/etc/apt/sources.list.d/passenger.listwith the following contents:
deb https://oss-binaries.phusionpassenger.com/apt/passenger jessie main
Enable HTTPS support for APT:
sudo apt-get install apt-transport-https
Update the local package database and install Phusion Passenger:
sudo apt-get update sudo apt-get install nginx-extras passenger
Run the Phusion Passenger installer for Nginx:
This starts the Phusion Passenger Nginx installer program. Press “Enter” to continue with the installation.
The installation process will begin an interactive session that will navigate through the process of building Phusion Passenger. When prompted for the Nginx installation method, we recommend selecting “1” for both options to allow the installer to automatically download, compile, and install Nginx.
Enable Passenger Support and Start Nginx
Nginx is now installed on the system, but support for Phusion Passenger is not enabled. As root, or with the
sudocommand, edit the file
/etc/nginx/nginx.confand uncomment these lines:
passenger_root /usr/lib/ruby/vendor_ruby/phusion_passenger/locations.ini; passenger_ruby /usr/bin/passenger_free_ruby;
sudo systemctl restart nginx
To verify that Passenger support has been installed and enabled correctly:
If Passenger is running, a few running processes should be displayed under the “Passenger processes” section:
1 2 3 4 5 6
----- Passenger processes ----- PID VMSize Private Name ------------------------------- 14337 420.8 MB 1.1 MB Passenger watchdog 14340 559.3 MB 1.4 MB Passenger core 14345 292.5 MB 1.2 MB Passenger ust-router
The configuration file for Nginx is located at
/etc/nginx/nginx.conf. This file must be edited to add support for Rails applications. A default server is already configured in this file, and it also contains examples for alternate virtual host and SSL configurations.
Install MySQL Support (Optional)
If the application deployed uses MySQL, install the database server by following our MySQL on Debian 8 guide. Once it’s installed and configured properly, issue the following command:
sudo apt-get install libmysqlclient-dev
You may wish to consult the following resources for additional information on this topic. While these are provided in the hope that they will be useful, please note that we cannot vouch for the accuracy or timeliness of externally hosted materials.
- Ruby on Rails Home Page
- Ruby on Rails Documentation
- Nginx Home Page
- Nginx Documentation
- Nginx Configuration
This guide is published under a CC BY-ND 4.0 license.