Ruby on Rails with Nginx on Ubuntu 12.04 LTS (Precise)

Updated , by Jonathan Frederickson
Select distribution:
Traducciones al Español
Estamos traduciendo nuestros guías y tutoriales al Español. Es posible que usted esté viendo una traducción generada automáticamente. Estamos trabajando con traductores profesionales para verificar las traducciones de nuestro sitio web. Este proyecto es un trabajo en curso.
Deprecated

This guide has been deprecated and is no longer being maintained.

Create a Linode account to try this guide with a $ credit.
This credit will be applied to any valid services used during your first  days.

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.

Note
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 sudo command, you can check our Users and Groups guide.

Before You Begin

  1. Follow the Getting Started and Securing Your Server guides, and set the Linode’s hostname.

    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).

  2. Update the system:

    sudo apt-get update && sudo apt-get upgrade
    
  3. 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

  1. 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.

  2. 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
    
  3. With sudo, or as the root user, create the file /etc/apt/sources.list.d/passenger.list containing Phusion’s repository info:

    File: /etc/apt/sources.list.d/passenger.list
    deb https://oss-binaries.phusionpassenger.com/apt/passenger precise main
  4. Update your local package database and install Phusion Passenger:

    sudo apt-get update
    sudo apt-get install nginx-extras passenger
    
  5. Run the Phusion Passenger installer for Nginx:

    sudo passenger-install-nginx-module
    

    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

  1. Nginx is now installed on your system, but you need to enable support for Phusion Passenger. Edit the file /etc/nginx/nginx.conf and uncomment these lines:

    File: /etc/nginx/nginx.conf
    1
    2
    
    passenger_root /usr/lib/ruby/vendor_ruby/phusion_passenger/locations.ini;
    passenger_ruby /usr/bin/ruby;
  2. Restart Nginx:

    sudo service nginx restart
    
  3. Verify that Passenger support has been installed and enabled correctly:

    sudo passenger-memory-stats
    

    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

More Information

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.

This page was originally published on


Your Feedback Is Important

Let us know if this guide was helpful to you.


Join the conversation.
Read other comments or post your own below. Comments must be respectful, constructive, and relevant to the topic of the guide. Do not post external links or advertisements. Before posting, consider if your comment would be better addressed by contacting our Support team or asking on our Community Site.