Install Ruby on Rails with Apache on Debian 8
Updated by Elle Krout Written by Linode
DeprecatedThis guide has been deprecated and is no longer being maintained.Please refer to the updated version of this guide.
Ruby on Rails is a rapid development web framework that allows web designers and developers to implement dynamic fully featured web applications. This guide deploys Rails applications using the Phusion Passenger or
mod_rails method. Passenger allows you to embed Rails apps directly in Apache applications without needing to worry about FastCGI or complex web server proxies.
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 sudo command, you can check our Users and Groups guide.
Before You Begin
To check your hostname run:
hostname hostname -f
The first command should show your short hostname, and the second should show your fully qualified domain name (FQDN).
Have a working Apache server. Follow the Apache Web Server on Debian 8 guide if needed.
Update your system:
sudo apt-get update && sudo apt-get upgrade
Installing Passenger and Dependencies
Install the system packages required for using Ruby, building Ruby modules, and running Rails applications:
sudo apt-get install build-essential libapache2-mod-passenger apache2 ruby ruby-dev libruby zlib1g-dev libsqlite3-dev
gempackage manager for Ruby modules, install the
sudo gem install fastthread
Install Ruby On Rails:
sudo gem install rails
If you require a specific version of Ruby On Rails, issue one of the following commands for the version you need:
gem install rails –version 2.1.2 gem install rails –version 2.2.2 gem install rails –version 2.3.5 gem install rails –version 3.0.4
This will install the appropriate versions of all required packages including ruby, rack, and other dependencies needed for basic Rails development.
(Optional) Install additional dependencies for your application, such as MySQL support:
sudo apt-get install mysql-server libmysqlclient-dev mysql-client mysql-common sudo gem install mysql
Any other dependencies can be installed mimicking the steps above: Install the needed packages, then the needed gem.
railsto your $PATH environment variable. Make sure to replace
VERSIONwith the version of Ruby you are running:
ls /var/lib/gems PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/var/lib/gems/VERSION/bin"
The step above will only add this PATH to your current session. To retain the change persistently, add the PATH to your local ~/.bashrc file:
echo “PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/var/lib/gems/VERSION/bin” >> ~/.bashrc
In your website’s public folder start a new rails project, to ensure everything is properly configured. Replace
applicationwith your application’s name:
sudo rails new /var/www/html/example.com/public_html/application
Configuring Apache to Work with Passenger
If your Apache virtual hosts file(s) mimics the ones create in the Apache Web Server on Debian 8 guide, you will have a
<VirtualHost> block containing a
DocumentRoot value similar to
Open the file in a text editor, and edit the
DocumentRootto reflect the public directory of your application:
Restart Apache to ensure all settings have been loaded:
sudo systemctl restart apache2
Deploying Multiple Rails Apps
There are a number of strategies for deploying more than one Rails application using Passenger. The simplest approach requires running multiple distinct virtual hosts configured as above to host a single Rails app each. Alternatively, you may host multiple Rails apps within a single virtual host. This section covers the latter option.
RailsBaseURIdirectives that specify the path to your Rails application within the VirtualHost configuration as in the following example:
1 2 3 4
DocumentRoot /var/www/html/example.com/public_html/ RailsBaseURI /app1 RailsBaseURI /app2 RailsBaseURI /app3
These directives configure Passenger to run three Rails apps on the
example.comsite at the three locations specified.
public/directory of the application to a directory within the
ln -s /var/www/html/example.com/app1/public/ /var/www/html/example.com/public_html/app1/ ln -s /var/www/html/example.com/app1/app2/ /var/www/html/example.com/public_html/app2/ ln -s /var/www/html/example.com/app1/app3/ /var/www/html/example.com/public_html/app3/
Congratulations! You have successfully deployed Ruby On Rails applications with the Apache Web server and Passenger.
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.
Join our Community
This guide is published under a CC BY-ND 4.0 license.