Deploying a Ruby application
on Passenger + Apache
This guide teaches you how you can deploy your app to a server. This guide assumes that you have already done the following, and that you know how to do them:
- Passenger and Apache are already installed on the server.
- You have already transferred the application's code to the server.
- You have already installed Ruby.
- You have already installed all necessary dependencies that your application needs.
If you miss one of these prerequisites or don't know how to perform it, then we recommend you to follow the Deployment tutorial. The deployment tutorial is end-to-end guide and teaches you how to install every component.
Table of contents
- Loading...
Determine the Ruby command that Passenger should use
We need to tell Passenger which Ruby command it should use to run your app, just in case there are multiple Ruby interpreters on your system. Please run passenger-config about ruby-command
to find out which Ruby interpreter you are using. For example:
$ passenger-config about ruby-command passenger-config was invoked through the following Ruby interpreter: Command: /usr/local/rvm/gems/ruby-2.3.3/wrappers/ruby Version: ruby 2.3.3p85 (2015-02-26 revision 49769) [x86_64-linux] ...
Please take note of the path after "Command" (in this example, /usr/local/rvm/gems/ruby-2.3.3/wrappers/ruby
). You will need it in one of the next steps.
Deploying an app to a virtual host's root
To deploy an app to an Apache virtual host's root path, the following steps must be taken:
- Add a virtual host entry to your Apache configuration file.
- The virtual host's document root must point to your application's public subdirectory.
- The Apache per-directory permissions must allow access to this directory.
- MultiViews must be disabled for this directory.
Here is an example:
<VirtualHost *:80> ServerName yourserver.com # Tell Apache and Passenger where your app's 'public' directory is DocumentRoot /path-to-your-app/public PassengerRuby /path-to-ruby # Relax Apache security settings <Directory /path-to-your-app/public> Allow from all Options -MultiViews # Uncomment this if you're on Apache > 2.4: #Require all granted </Directory> </VirtualHost>
Replace yourserver.com
with your server's host name, and replace /path-to-your-app
with your application's code directory path. However, make sure that Apache is configured to point to the public
subdirectory inside it!
Replace /path-to-ruby
with the Ruby command that you obtained in Determine the Ruby command that Passenger should use.
When you are done, restart Apache:
$ sudo apachectl restart
(Depending on your operating system, the right command may be apache2ctl
instead of apachectl
.)
You are now done. If you run into any problems, please refer to the troubleshooting guide.
Deploying an app to a sub-URI or subdirectory
You can also deploy an app to a sub-URI instead of the root URI. For example, suppose that you already have a virtual host for the application /websites/phusion
:
<VirtualHost *:80>
ServerName www.phusion.nl
DocumentRoot /websites/phusion/public
<Directory /websites/phusion>
Allow from all
Options -MultiViews
# Uncomment this if you're on Apache >= 2.4:
#Require all granted
</Directory>
</VirtualHost>
And you want your application, located in /websites/secondapp
, to be accessible from the URL http://www.phusion.nl/subpath
. To do this, you need to perform the following:
- Set
Alias {SUBURI} {PATH TO YOUR APPLICATION'S PUBLIC DIRECTORY}
. - Create a
<Location /{SUBURI}> block
. - Inside the Location block, set
PassengerBaseURI /{SUBURI}
. - Inside the Location block, set
PassengerAppRoot {PATH TO YOUR APPLICATION ROOT}
. - Create a
<Directory {PATH TO YOUR APPLICATION PUBLIC SUBDIRECTORY}>
block. - Inside the Directory block, set
Allow from all
, and (if you’re on Apache >= 2.4)Require all granted
. - Inside the Directory block, disable MultiViews.
Here is an example:
<VirtualHost *:80> ServerName www.phusion.nl DocumentRoot /websites/phusion/public <Directory /websites/phusion> Allow from all Options -MultiViews # Uncomment this if you're on Apache >= 2.4: #Require all granted </Directory> # These have been added: Alias /subapp /websites/secondapp/public <Location /subapp> PassengerBaseURI /subapp PassengerAppRoot /websites/secondapp </Location> <Directory /websites/secondapp/public> Allow from all Options -MultiViews # Uncomment this if you're on Apache >= 2.4: #Require all granted </Directory> </VirtualHost>
When you are done, restart Apache:
$ sudo apachectl restart
(Depending on your operating system, the right command may be apache2ctl
instead of apachectl
.)
You are now done. If you run into any problems, please refer to the troubleshooting guide.