This document describes how to set up the Ruby on Rails Framework on an Arch Linux system.

This document describes how to set up the Ruby on Rails Framework on an Arch Linux system.

−

Ruby on Rails requires [[Ruby]] to be installed, so read that article first for installation instructions.

+

== Installation ==

−

== Option A: Installation via RubyGems (Recommended) ==

+

Ruby on Rails requires [[Ruby]] to be installed, so read that article first for installation instructions. The {{pkg|nodejs}} package is also required.

−

{{Box Note | If this command is run without being root (using sudo or otherwise), the gem will be installed into the home directory of the user.}}

+

Ruby on Rails itself can be installed multiple ways:

−

# gem install rails

+

=== Option A: via RubyGems ===

+

+

{{Note|You can also install Rails system-wide using Gems. To do this, run the following commands as root and append them with {{ic|--no-user-install}}. Please read [[Ruby#Installing gems per-user or system-wide]] for possible dangers of using RubyGem in this way.}}

+

+

The following command will install Rails for the current user:

+

$ gem install rails

Building the documentation takes a while. If you want to skip it, append the parameters --no-ri --no-rdoc to the install command.

Building the documentation takes a while. If you want to skip it, append the parameters --no-ri --no-rdoc to the install command.

−

# gem install rails --no-ri --no-rdoc

+

$ gem install rails --no-ri --no-rdoc

+

+

gem is a package manager for Ruby modules, somewhat like pacman is to Arch Linux. To update your gems, simply run:

+

$ gem update

−

=== Updating Gems ===

+

=== Option B: via pacgem ===

−

gem is a package manager for Ruby modules, somewhat like pacman is to Arch Linux. To update your gems, simply run:

+

You can install Rails using {{AUR|pacgem}} from the [[AUR]]. Pacgem automatically creates PKGBUILDs and Arch packages for each of the gems. These packages will then be installed using pacman.

−

# gem update

+

# pacgem rails

+

+

The gem packages can be updated with

+

# pacgem -u

−

== Option B: Installing via the AUR ==

+

=== Option C: from the AUR ===

{{Warning|This is not recommended, as this might not include the latest Rails version, and additional dependencies may be introduced that may require you to run {{Ic|gem install}} anyway.}}

{{Warning|This is not recommended, as this might not include the latest Rails version, and additional dependencies may be introduced that may require you to run {{Ic|gem install}} anyway.}}

−

There is a {{AUR|rails}} package available in the [[AUR]]. Note that this is not in an [[Official Repositories|official repository]], so you will need to [[AUR#Build_the_package|build it manually]].

+

+

There is a {{AUR|rails}} package available in the [[AUR]].

== Configuration ==

== Configuration ==

Line 32:

Line 44:

$ rails new testapp_name

$ rails new testapp_name

−

This makes a new folder in your current working directory. Next start the web server. It listens on port 3000 by default:

+

{{Note|If you get an error like {{ic|Errno::ENOENT: No such file or directory (...) An error occurred while installing x, and Bundler cannot continue.}}, you might have to configure [[Ruby#Bundler|Bundler]] so that it installs gems per-user and not system-wide. Alternatively, run {{ic|# rails new testapp_name}} once as root. If it has completed successfully, delete {{ic|testapp_name/}} and run {{ic|$ rails new testapp_name}} again as a regular user.}}

Finally open your server address on port 3000 in your web browser. For example, if you are working on your local machine, visit http://localhost:3000.

+

Now visit the testapp_name website on your local machine by opening http://localhost:3000 in your browser

−

{{Box Note | If ruby complains about not being able to fina a JavaScript runtime, do <code>$ pacman -S nodejs</code>.}}

+

{{Note|If Ruby complains about not being able to find a JavaScript runtime, install {{Pkg|nodejs}}.}}

A test-page should shown greeting you "Welcome aboard".

A test-page should shown greeting you "Welcome aboard".

Line 63:

Line 84:

# gem install unicorn

# gem install unicorn

−

Then create a configuration file for your application in /etc/unicorn/. For example; here is a configuration example (Based on [http://www.warden.pl/2011/01/07/running-redmine-under-unicorn-in-debian/]) for Redmine:

+

Then create a configuration file for your application in {{ic|/etc/unicorn/}}. For example; here is a configuration example (Based on [http://www.warden.pl/2011/01/07/running-redmine-under-unicorn-in-debian/]) for Redmine:

−

<pre>working_directory "/srv/http/redmine"

+

{{hc|/etc/unicorn/redmine.ru|<nowiki>

+

working_directory "/srv/http/redmine"

pid "/tmp/redmine.pid"

pid "/tmp/redmine.pid"

Line 84:

Line 106:

#Drop privileges if running as root

#Drop privileges if running as root

worker.user('nobody', 'nobody') if Process.euid == 0

worker.user('nobody', 'nobody') if Process.euid == 0

−

end</pre>

+

end

+

</nowiki>}}

Start it using:

Start it using:

# usr/bin/unicorn -D -E production -c /etc/unicorn/redmine.ru

# usr/bin/unicorn -D -E production -c /etc/unicorn/redmine.ru

+

+

==== Systemd service ====

+

Put the following contents in {{ic|/etc/systemd/system/unicorn.service}}:

After setting up [[Nginx]], configure unicorn as an upstream server using something like this (Warning: this is a stripped example. It probably doesn't work without additional configuration):

+

{{bc|1=

+

http {

+

upstream unicorn {

+

server 127.0.0.1:4000 fail_timeout=0;

+

server 127.0.0.1:4001 fail_timeout=0;

+

server 127.0.0.1:4002 fail_timeout=0;

+

server 127.0.0.1:4003 fail_timeout=0;

+

}

+

+

server {

+

listen 80 default;

+

server_name YOURHOSTNAMEHERE;

+

+

location / {

+

root /srv/http/redmine/public;

+

proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

+

proxy_set_header Host $http_host;

+

proxy_redirect off;

+

proxy_pass http://unicorn;

+

}

+

}

+

}

+

}}

=== Apache/Nginx (using Phusion Passenger) ===

=== Apache/Nginx (using Phusion Passenger) ===

Line 94:

Line 161:

{{note|The current Nginx package in the official repositories actually is compiled with the Passenger module, so you can install it via pacman. The configuration files are stored in {{ic|/etc/nginx/conf/}}.}}

{{note|The current Nginx package in the official repositories actually is compiled with the Passenger module, so you can install it via pacman. The configuration files are stored in {{ic|/etc/nginx/conf/}}.}}

+

{{note|As of 2013-10-07 this doesn't seem to be the casy any longer and you will have to follow the remaining steps here}}

Start by installing the 'passenger' gem:

Start by installing the 'passenger' gem:

Line 100:

Line 168:

If you are aiming to use [[Apache]], run:

If you are aiming to use [[Apache]], run:

# passenger-install-apache2-module

# passenger-install-apache2-module

+

+

In case a rails application is deployed with a sub-URI, like http://example.com/yourapplication, some additional configuration is required, see [http://www.modrails.com/documentation/Users%20guide%20Apache.html#deploying_rails_to_sub_uri the modrails documentation]

For [[Nginx]]:

For [[Nginx]]:

Line 125:

Line 195:

=== PostgreSQL ===

=== PostgreSQL ===

−

−

(Stub.)

Install {{Pkg|postgresql}}.

Install {{Pkg|postgresql}}.

Line 132:

Line 200:

=== MySQL ===

=== MySQL ===

−

{{Note|You must first install [[MySQL]] with the appropriate headers in {{ic|/usr/include}} (just installing {{Pkg|mysql}} is fine) before attempting to install the Ruby MySQL extensions.}}

+

First, install and configure a MySQL server. Please refer to [[MySQL]] on how to do this.

−

−

Please refer to [[MySQL]] on how to install MySQL Server.

A gem with some native extensions is required, probably best installed as root:

A gem with some native extensions is required, probably best installed as root:

−

# sudo gem install mysql

+

# gem install mysql

−

You can generate a rails application configured for MySQL by using the {{Ic|-d}} parameter:

+

You can generate a rails application configured for MySQL by using the {{ic|-d}} parameter:

$ rails new testapp_name -d mysql

$ rails new testapp_name -d mysql

−

You then need to edit config/database.yml. Rails uses different databases for development, testing, production and other environments. Here is an example development configuration for MySQL running on localhost:

+

You then need to edit {{ic|config/database.yml}}. Rails uses different databases for development, testing, production and other environments. Here is an example development configuration for MySQL running on localhost:

development:

development:

Line 155:

Line 221:

If no errors are shown, then your database has been created and Rails can talk to your MySQL database.

If no errors are shown, then your database has been created and Rails can talk to your MySQL database.

−

== Option C: The Perfect Rails Setup ==

+

== The Perfect Rails Setup ==

''Phusion Passenger running multiple Ruby versions.''

''Phusion Passenger running multiple Ruby versions.''

Line 162:

Line 228:

* [http://www.nginx.org/ Nginx]: A fast and lightweight '''web server''' with a strong focus on high concurrency, performance and low memory usage.

* [http://www.nginx.org/ Nginx]: A fast and lightweight '''web server''' with a strong focus on high concurrency, performance and low memory usage.

* [http://www.modrails.com/ Passenger] (a.k.a. mod_rails or mod_rack): Supports both Apache and Nginx web servers. It makes deployment of Ruby web applications, such as those built on Ruby on Rails web framework, a breeze.

* [http://www.modrails.com/ Passenger] (a.k.a. mod_rails or mod_rack): Supports both Apache and Nginx web servers. It makes deployment of Ruby web applications, such as those built on Ruby on Rails web framework, a breeze.

−

* [http://www.rubyenterpriseedition.com/ Ruby Enterprise Edition] (REE): Passenger allows Ruby on Rails applications to use about 33% less memory, when used in combination with REE.

+

* [https://rvm.io/ Ruby Version Manager] (RVM): A command-line tool which allows you to easily install, manage, and work with multiple Ruby environments from interpreters to sets of gems. RVM lets you deploy each project with its own completely self-contained and dedicated environment —from the specific version of ruby, all the way down to the precise set of required gems to run your application—.

−

* [http://rvm.beginrescueend.com/ Ruby Version Manager] (RVM): A command-line tool which allows you to easily install, manage, and work with multiple Ruby environments from interpreters to sets of gems. RVM lets you deploy each project with its own completely self-contained and dedicated environment —from the specific version of ruby, all the way down to the precise set of required gems to run your application—.

{{Note|During the installation of Ruby patches will be applied. Consider installing the {{ic|base-devel}} group beforehand.}}

−

−

$ rvm install ree

−

. Also take the chance to include other interpreters you want to use, like the last Ruby version

−

$ rvm install 1.9.3

−

−

==== Advice ====

−

−

There is a documented [https://bugs.ruby-lang.org/issues/6383#note-1 bug] with older versions of Ruby (ie. the 1.8.7 version that REE uses) and the GCC versions 4.6 and up. If you get segmentation fault errors when trying to install gems such as Passenger, remove your install of REE and reinstall with the following:

It is also possible to make it work with older versions of GCC, but that requires considerably more time.

+

$ rvm install 2.0.0

−

I have found useful to delete the 'global' gemsets of the environments that have web applications. Their gems were somehow interfering with Passenger. Do not do

+

{{Note| It may be useful to delete the 'global' gemsets of the environments that have web applications. Their gems might somehow interfere with Passenger. In that case, a {{ic|rvm 2.0.0 do gemset delete global}} is sufficient.}}

−

$ rvm ree do gemset delete global

−

$ rvm 1.9.3 do gemset delete global

−

now, but consider this later if you encounter complications.

=== Step 3: Nginx with Passenger support ===

=== Step 3: Nginx with Passenger support ===

−

Do not install Nginx via pacman. This web server does not support modules as Apache, so it must be compiled from source with the functionality of ''mod_rails'' (Passenger). Fortunately this is straightforward thanks to the passenger gem. Get it:

+

Run the following to allow passenger install nginx:

−

$ rvm use ree

+

$ rvm use 2.0.0

$ gem install passenger

$ gem install passenger

−

. The gem will be put into the 'default' gemset. Now execute the following script:

+

$ rvmsudo passenger-install-nginx-module

−

{{note|The current nginx package in the official repos actually was compiled with the passenger module. So you can install it via pacman and skip this step. The config files are stored in /etc/nginx/conf/. }}

+

The passenger gem will be put into the ''default'' gemset.

−

$ rvmsudo passenger-install-nginx-module

+

This will download the sources of Nginx, compile and install it for you. It will guide you through all the process. Note that the default location for Nginx will be {{ic|/opt/nginx}}.

−

. It will download the sources of Nginx, compile and install it for you. It will guide you through all the process. (The default location for Nginx is /opt/nginx.)

If you installed [[Nginx]] from pacman the {{ic|passenger_root}} needs to be changed to:

+

=== Step 4: Gemsets and Apps ===

−

passenger_root /usr/lib/passenger/;

−

{{warning|Do not set it to {{ic|/usr/lib/passenger/bin/passenger}} since this will result in [[Nginx]] segfaulting when checking the config}}

−

−

For everything that is not Ruby, use [[Nginx]] as usual to serve static pages, PHP and Python. Check the wiki page for more information.

−

−

To enable the Nnginx service by default at start-up just add {{Ic|nginx}} to the {{Ic|DAEMONS}} array in {{ic|/etc/rc.conf}}:

−

DAEMONS=(ntpd syslog-ng ... nginx)

−

−

If you are using {{Ic|systemd}} instead of {{Ic|initscripts}}, you must run the following command to have your system run {{Ic|nginx}} on startup

−

# systemctl enable nginx.service

+

For each Rails application you should have a gemset. Suppose that you want to try [http://refinerycms.com RefineryCMS] against [http://www.browsercms.org BrowserCMS], two open-source Content Management Systems based on Rails.

−

{{note|It is possible that your Nginx installation has not come with an init script; check your /etc/rc.d/ directory for a file called ''nginx'', if that is your case manually create it. Help yourself with [[Nginx/Init_script]]. If you installed nginx to another location, such as /opt/nginx, you will need to edit the init script accordingly.}}

+

Install RefineryCMS first:

−

−

=== Step 4: Gemsets and Apps ===

−

For each Rails application you should have a gemset. Suppose that you want to try [http://refinerycms.com RefineryCMS] against [http://www.browsercms.org BrowserCMS], two open-source Content Management Systems based on Rails. Then you should do:

+

$ rvm use 2.0.0@refinery --create

−

$ rvm use ree@refinery --create

+

$ gem install rails -v 4.0.1

−

$ gem install rails -v 3.0.11

$ gem install passenger

$ gem install passenger

$ gem install refinerycms refinerycms-i18n sqlite3

$ gem install refinerycms refinerycms-i18n sqlite3

+

Deploy a RefineryCMS instance called ''refineria'':

Deploy a RefineryCMS instance called ''refineria'':

+

$ cd /srv/http/

$ cd /srv/http/

$ rvmsudo refinerycms refineria

$ rvmsudo refinerycms refineria

−

Again:

+

−

$ rvm use 1.9.3@browser --create

+

Install BrowserCMS in a different gemset:

+

+

$ rvm use 2.0.0@browser --create

+

$ gem install rails -v 4.0.1

$ gem install passenger

$ gem install passenger

$ gem install browsercms sqlite3

$ gem install browsercms sqlite3

+

Deploy a BrowserCMS instance called ''navegador'':

Deploy a BrowserCMS instance called ''navegador'':

+

$ cd /srv/http/

$ cd /srv/http/

$ rvmsudo browsercms demo navegador

$ rvmsudo browsercms demo navegador

Line 267:

Line 313:

Observe that the passenger gem was installed three times and with different intentions; in the environments

Observe that the passenger gem was installed three times and with different intentions; in the environments

−

* ''ree'' => for Nginx,

+

* ''2.0.0'' => for Nginx,

−

* ''ree@refinery'' => Standalone, and

+

* ''2.0.0@refinery'' => Standalone

−

* ''1.9.3@browser'' => Standalone.

+

* ''2.0.0@browser'' => Standalone

−

The strategy is to combine Passenger for Nginx with Passenger Standalone. One must first identify the Ruby environment (interpreter plus gemset) that one uses the most; in this setup the REE interpreter and the default gemset were selected. One then proceeds with setting up Passenger for Nginx to use that environment (step 3).

+

The strategy is to combine Passenger for Nginx with Passenger Standalone. One must first identify the Ruby environment (interpreter plus gemset) that one uses the most; in this setup the Ruby interpreter and the default gemset were selected. One then proceeds with setting up Passenger for Nginx to use that environment (step 3).

* Applications within the chosen environment can be served as in [[Ruby_on_Rails#Apache.2FNginx_.28using_Phusion_Passenger.29|Apache/Nginx (using Phusion Passenger)]], page up in this article.

* Applications within the chosen environment can be served as in [[Ruby_on_Rails#Apache.2FNginx_.28using_Phusion_Passenger.29|Apache/Nginx (using Phusion Passenger)]], page up in this article.

* All applications that are to use a different Ruby version and/or gemset can be served separately through Passenger Standalone and hook into the main web server via a reverse proxy configuration (step 6).

* All applications that are to use a different Ruby version and/or gemset can be served separately through Passenger Standalone and hook into the main web server via a reverse proxy configuration (step 6).

Line 282:

Line 328:

Create /srv/http/refineria/.rvmrc doing

Create /srv/http/refineria/.rvmrc doing

−

sudo sh -c 'echo "rvm ree@refinery" > /srv/http/refineria/.rvmrc'

+

# echo "rvm ree@refinery" > /srv/http/refineria/.rvmrc

, and /srv/http/navegador/.rvmrc with

, and /srv/http/navegador/.rvmrc with

−

sudo sh -c 'echo "rvm 1.9.3@browser" > /srv/http/navegador/.rvmrc'

+

# echo "rvm 2.0.0@browser" > /srv/http/navegador/.rvmrc

You have to enter to both application root folders now, because every first time that RVM finds a .rvmrc it asks you if you trust the given file, consequently you must validate the two files you have just created.

You have to enter to both application root folders now, because every first time that RVM finds a .rvmrc it asks you if you trust the given file, consequently you must validate the two files you have just created.

Line 290:

Line 336:

Apart, if applications' files and folders are not owned by the right user you will face database write-access problems. The use of rvmsudo produces ''root''-owned archives when generated by Rails; in the other hand, ''nobody'' is the user for Passenger —if you have not changed it—: who will use and should posses them. Fix this doing

Apart, if applications' files and folders are not owned by the right user you will face database write-access problems. The use of rvmsudo produces ''root''-owned archives when generated by Rails; in the other hand, ''nobody'' is the user for Passenger —if you have not changed it—: who will use and should posses them. Fix this doing

Once again edit /opt/nginx/conf/nginx.conf to include some vital instructions:

Once again edit /opt/nginx/conf/nginx.conf to include some vital instructions:

Line 377:

Line 423:

}}

}}

−

== Without subdomains ==

+

==== Without subdomains ====

If you for some reason don't want to host each application on it's own subdomain but rather in a url like: {{ic|site.com/railsapp}} then you could do something like this in your config:

If you for some reason don't want to host each application on it's own subdomain but rather in a url like: {{ic|site.com/railsapp}} then you could do something like this in your config:

Line 409:

Line 455:

At this point you are in conditions to run Nginx with:

At this point you are in conditions to run Nginx with:

−

$ sudo rc.d start nginx

+

# systemctl start nginx

and to access both CMSs through ''refinery.domain.com'' and ''browser.domain.com''.

and to access both CMSs through ''refinery.domain.com'' and ''browser.domain.com''.

Revision as of 19:51, 8 December 2013

zh-CN:Ruby on RailsRuby on Rails, often shortened to Rails or RoR, is an open source web application framework for the Ruby programming language. It is intended to be used with an Agile development methodology that is used by web developers for rapid development.

This document describes how to set up the Ruby on Rails Framework on an Arch Linux system.

Installation

Ruby on Rails requires Ruby to be installed, so read that article first for installation instructions. The nodejs package is also required.

Ruby on Rails itself can be installed multiple ways:

Option A: via RubyGems

Note: You can also install Rails system-wide using Gems. To do this, run the following commands as root and append them with --no-user-install. Please read Ruby#Installing gems per-user or system-wide for possible dangers of using RubyGem in this way.

The following command will install Rails for the current user:

$ gem install rails

Building the documentation takes a while. If you want to skip it, append the parameters --no-ri --no-rdoc to the install command.

$ gem install rails --no-ri --no-rdoc

gem is a package manager for Ruby modules, somewhat like pacman is to Arch Linux. To update your gems, simply run:

$ gem update

Option B: via pacgem

You can install Rails using pacgemAUR from the AUR. Pacgem automatically creates PKGBUILDs and Arch packages for each of the gems. These packages will then be installed using pacman.

# pacgem rails

The gem packages can be updated with

# pacgem -u

Option C: from the AUR

Warning: This is not recommended, as this might not include the latest Rails version, and additional dependencies may be introduced that may require you to run gem install anyway.

Configuration

Rails is bundled with a basic HTTP server called WeBrick. You can create a test application to test it. First, create an application with the rails command:

$ rails new testapp_name

Note: If you get an error like Errno::ENOENT: No such file or directory (...) An error occurred while installing x, and Bundler cannot continue., you might have to configure Bundler so that it installs gems per-user and not system-wide. Alternatively, run # rails new testapp_name once as root. If it has completed successfully, delete testapp_name/ and run $ rails new testapp_name again as a regular user.

Now visit the testapp_name website on your local machine by opening http://localhost:3000 in your browser

Note: If Ruby complains about not being able to find a JavaScript runtime, install nodejs.

A test-page should shown greeting you "Welcome aboard".

Application servers

While the default Ruby On Rails HTTP server (WeBrick) is convenient for basic development it is not recommended for production use. Generally, you should choose between installing the Phusion Passenger module for your webserver (Apache or Nginx), or use a dedicated application-server (such as Mongrel or Unicorn) combined with a separate web-server acting as a reverse proxy.

Mongrel

Mongrel is a drop-in replacement for WeBrick, that can be run in precisely the same way, but offers better performance.

First install the Mongrel gem:

# gem install mongrel

Then start it using:

# mongrel_rails start

Alternatively, you can just run "ruby script/server" again, as it replaces WeBrick by default.

Apache/Nginx (using Phusion Passenger)

Passenger also known as mod_rails is a module available for Nginx and Apache, that greatly simplifies setting up a Rails server environment. Nginx does not support modules as Apache and has to be compiled with mod_rails in order to support Passenger; let Passenger compile it for you. As for Apache, let Passenger set up the module for you.

Note: The current Nginx package in the official repositories actually is compiled with the Passenger module, so you can install it via pacman. The configuration files are stored in /etc/nginx/conf/.

Note: As of 2013-10-07 this doesn't seem to be the casy any longer and you will have to follow the remaining steps here

Databases

Most web applications will need to interact with some sort of database. ActiveRecord (the ORM used by Rails to provide database abstraction) supports several database vendors, the most popular of which are MySQL, SQLite, and PostgreSQL.

SQLite

SQLite is the default lightweight database for Ruby on Rails. To enable SQLite, simply install sqlite3.

PostgreSQL

MySQL

First, install and configure a MySQL server. Please refer to MySQL on how to do this.

A gem with some native extensions is required, probably best installed as root:

# gem install mysql

You can generate a rails application configured for MySQL by using the -d parameter:

$ rails new testapp_name -d mysql

You then need to edit config/database.yml. Rails uses different databases for development, testing, production and other environments. Here is an example development configuration for MySQL running on localhost:

The Perfect Rails Setup

Nginx: A fast and lightweight web server with a strong focus on high concurrency, performance and low memory usage.

Passenger (a.k.a. mod_rails or mod_rack): Supports both Apache and Nginx web servers. It makes deployment of Ruby web applications, such as those built on Ruby on Rails web framework, a breeze.

Ruby Version Manager (RVM): A command-line tool which allows you to easily install, manage, and work with multiple Ruby environments from interpreters to sets of gems. RVM lets you deploy each project with its own completely self-contained and dedicated environment —from the specific version of ruby, all the way down to the precise set of required gems to run your application—.

Step 1: RVM

http and nobody are the users related to Nginx and Passenger, respectively.

Note: Maybe adding the 'nobody' user to the 'rvm' group is not necessary.

Step 2: Rubies

Once you have a working RVM installation in your hands, it is time to install the latest Ruby interpreter

Note: During the installation of Ruby patches will be applied. Consider installing the base-devel group beforehand.

$ rvm install 2.0.0

Note: It may be useful to delete the 'global' gemsets of the environments that have web applications. Their gems might somehow interfere with Passenger. In that case, a rvm 2.0.0 do gemset delete global is sufficient.

Passenger for Nginx and Passenger Standalone

Observe that the passenger gem was installed three times and with different intentions; in the environments

2.0.0 => for Nginx,

2.0.0@refinery => Standalone

2.0.0@browser => Standalone

The strategy is to combine Passenger for Nginx with Passenger Standalone. One must first identify the Ruby environment (interpreter plus gemset) that one uses the most; in this setup the Ruby interpreter and the default gemset were selected. One then proceeds with setting up Passenger for Nginx to use that environment (step 3).

All applications that are to use a different Ruby version and/or gemset can be served separately through Passenger Standalone and hook into the main web server via a reverse proxy configuration (step 6).

Step 5: .rvmrc files and ownerships

This step is crucial for the correct behaviour of the setup. RVM seeks for .rvmrc files when changing folders; if it finds one, it reads it. In these files normally one stores a line like

rvm <ruby_version>@<gemset_name>

so the specified environment is set at the entrance of applications' root folder.

Create /srv/http/refineria/.rvmrc doing

# echo "rvm ree@refinery" > /srv/http/refineria/.rvmrc

, and /srv/http/navegador/.rvmrc with

# echo "rvm 2.0.0@browser" > /srv/http/navegador/.rvmrc

You have to enter to both application root folders now, because every first time that RVM finds a .rvmrc it asks you if you trust the given file, consequently you must validate the two files you have just created.

These files aid the programs involved to find the correct gems.

Apart, if applications' files and folders are not owned by the right user you will face database write-access problems. The use of rvmsudo produces root-owned archives when generated by Rails; in the other hand, nobody is the user for Passenger —if you have not changed it—: who will use and should posses them. Fix this doing

# chown -R nobody.nobody /srv/http/refineria /srv/http/navegador

Step 6: Reverse proxies

You have to start the Passenger Standalone web servers for your applications. So, do

. The first time that you run a Passenger Standalone it will perform a minor installation.

Note that you are using unix domain sockets instead of the commonly-used TCP sockets; it turns out that unix domain are significantly faster than TCP sockets.

Note: If you are experimenting trouble with unix sockets, changing to TCP should work:

rvmsudo passenger start -a 127.0.0.1 -p 3000 -d

Launch Passenger Standalone daemons at system start-up

Do you have a script? Please post it here.

The systemd script below was made for a Typo blog I host at /srv/http/typo. It's located at /etc/systemd/system/passenger_typo.service. I set the Environment= tags (see "man systemd.exec") from the output of "rvm env". The only exception was PATH=, which I had to combine from my regular PATH and the output of rvm env.

Note: If you don't set the "WorkingDirectory=" variable to your application folder, passenger will fail to find your app and will subsequently shut itself down.