Ruby on Rails with Nginx on Ubuntu 12.04 LTS (Precise)
Updated by Alex Fornuto Written by Jonathan Frederickson
DeprecatedThis guide has been deprecated and is no longer being maintained.
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 Phusion Passenger and the Nginx web server on Debian 8.
NoteThis 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. Phusion Passenger includes their own build of Nginx which supports loadable modules:
sudo apt-get remove nginx nginx-full nginx-light nginx-naxsi 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 ruby1.8 ruby1.8-dev zlib1g-dev rubygems1.8 libruby libssl-dev libpcre3-dev libcurl4-openssl-dev rake ruby-rack rails
Additionally, the application you deploy will likely have additional dependencies. Install these dependencies before proceeding.
Phusion hosts a repository containing the latest version of Phusion Passenger. To add this to your package manager, first install the Phusion PGP key:
sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 561F9B9CAC40B2F7
sudo, or as the root user, create the file
/etc/apt/sources.list.d/passenger.listcontaining Phusion’s repository info:
deb https://oss-binaries.phusionpassenger.com/apt/passenger precise main
Update your 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:
You’ll be greeted by the Phusion Passenger Nginx installer program. Press Enter to continue with the installation:
The installation process will begin an interactive session that will guide you through the process of building Phusion Passenger. When prompted for the Nginx installation method, it is recommended that you choose 1 for both options to allow the installer to automatically download, compile, and install Nginx for you.
Enable Passenger Support and Start Nginx
Nginx is now installed on your system, but you need to enable support for Phusion Passenger. 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/ruby;
sudo service nginx restart
Verify that Passenger support has been installed and enabled correctly:
If Passenger is running, you should see a few running processes under the Passenger processes section.
The configuration file for Nginx is located at
/etc/nginx/nginx.conf. This is the file you’ll need to edit to add support for your 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 your application uses MySQL, install the database server by following our MySQL on Ubuntu 12.04 (Precise) guide. Once it’s installed and configured properly, issue the following command:
sudo apt-get install libmysqlclient-dev libmysql-ruby
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
Join our Community
This guide is published under a CC BY-ND 4.0 license.