Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

My goal is to run ruby applications under different server users with potentially different versions of ruby.

So i would have users that serve as the "hosting account" essentially. Document root/application files will live in their home directory along with ruby version(s) and gemsets managed with RVM. A user will have one or more web apps it needs to run. The virtual hosts for this user's site will point to the document root in the users home dir and webserver will also effectively run as this user:group.

Example layout:

       [ other rails dirs ]
     /somephpapp (symfony, zf, etc.)
       [ other framework dirs ]
    /railsapp1.com (ln -s ../applications/railsapp1/public)
    /somephpapp.com (ln -s ../applications/somephpapp/public)


Question 1: I this even possible? I know passenger supports ruby versions and passenger users (i assume the passenger user equiv to specifying the user:group for fcgi, php-fpm, SuExec) at the virtual host level but all the intstuctions im finding seem to install the apache module from a specific RVM user, that seems odd. Or is it just a matter of creating a generic user to install the module from and then doing everything else on a per account basis?

Question 2: Even if this is possible is the correct way to set things up? Whats the best practice here given that:

  1. The webserver/application MUST run as a given account's user:group
  2. MUST have the ability to run different version of ruby on per application basis
  3. Each user MUST be able to run multiple applications
  4. Each application MUST be contained under a specific user's home dir
  5. The user MUST be sandboxed to his/her homedir (not a sodoer)

(Note: I myself am not a ruby dev/user aside from the odd shell script here or there or using compass/zurb-foundation so Im open to options other than Passenger. Also this server is not intended as a production environment.)

share|improve this question
Do you need to use Passenger ? I know what you want to do is achieved quite enough easily with Unicorn. github.com/blog/517-unicorn unicorn.bogomips.org/Unicorn/Configurator.html#method-i-user –  Yannovitch Jun 6 '13 at 6:54
@Yannovitch: No there is no definite reason i need to use Passenger, beyond the fact the i would prefer as little configuration as possible outside of httpd.conf and virtual host configurations. My main need right now is to just get redmine up and running. But at some point i know ill need to stage another ruby app for something, whether its a private system like redmine or a project a client needs to review. I'm just trying to find a setup that can accommodate this regardless. –  prodigitalson Jun 6 '13 at 14:40
I'd just proxy to thin, myself. –  Michael Hampton Jun 6 '13 at 19:42

1 Answer 1

up vote 3 down vote accepted

When I initially posted this i was trying to save the time of going down this path for the setup only to have it not work. After a couple days I just gave it a shot and it worked. What i did was:

Create a user to actually install passenger from. I suspect you could use root for this but i created a standalone admin level user called passenger. I also disabled all remote access for this user.

sudo useradd -m -s /bin/bash passenger

Switch to the new passenger user and install rvm and use it to install my preferred default ruby (1.9.3-stable):

su - passenger
curl -L https://get.rvm.io | bash
rvm install 1.9.3

Install passenger and the apache module:

gem install passenger

Add the passenger mod files to /etc/apache2/mods-available... The .load file:

# /etc/apache2/mods-available/passenger.load
LoadModule passenger_module /home/passenger/.rvm/gems/ruby-1.9.3-p429/gems/passenger-4.0.5/libout/apache2/mod_passenger.so

The .conf file:

# /etc/apache2/mods-available/passenger.conf

PassengerRoot /home/passenger/.rvm/gems/ruby-1.9.3-p429/gems/passenger-4.0.5
PassengerDefaultRuby /home/passenger/.rvm/wrappers/ruby-1.9.3-p429/ruby
PassengerUserSwitching on
PassengerDefaultUser www-data
PassengerDefaultGroup www-data

# Any other global-only configuration

Then i enabled the module and ran a config test, followed by a reload if successful

sudo a2enmod passenger
sudo apache2ctl configtest
sudo service apache2 graceful # if Syntax Ok from previous command

After this I configured my virtual host as needed... example:

<VirtualHost *:80>
    ServerName appname.yourdomain.com
    ServerAdmin appuser@yourdomain.com
    DocumentRoot /home/appuser/path/to/doc/root

    PassengerSpawnMethod smart
    PassengerPoolIdleTime 300
    PassengerMaxRequests 500
    PassengerStatThrottleRate 5
    PassengerMinInstances 2
    PassengerRuby /home/appuser/.rvm/rubies/ruby-1.9.3-p429/bin/ruby

    <Directory "/home/appuser/path/to/doc/root">
        Options Indexes -ExecCGI FollowSymLinks -MultiViews
        Order allow,deny
        Allow from all

Since PassengerUserSwitching is on and the PassengerRuby is owned by a different user, passenger will automatically run the application as this user:group. However, there are specific passenger directives you can use to set user and group at the vhost level. Whether or not those need to match the owner of the PassengerRuby i do not know for sure.

Articles/Docs that helped:

  1. Multiple Rubies with a single Passenger
  2. How To Install Redmine on Ubuntu 11.10 Server using Apache and mod_passenger with performance improving options (Used mainly to help configure performance type settings)
  3. Phusion Passenger Configuration Reference (Apache)
share|improve this answer
Two years later: Any experiences with that? Still a good approach? –  Robert Schneider May 20 at 7:54
@RobertSchneider: Still alive and kicking! I havent run in to any issues that I recall. I pretty much just needed to run Redmine, but i wanted to have something expandable in case i needed to stage a different ruby project to that box. I never have needed to deploy a second ruby project so my experiences may be limited. –  prodigitalson May 20 at 12:16
I have the same requirement regarding potential ruby web applications that I want to add. I think your solution is quite good. +1 from me! –  Robert Schneider May 20 at 12:30
@RobertSchneider Awesome, glad it helped. I'd be interested to know if you run in to any issues with this set up as time passes as well. –  prodigitalson May 20 at 14:34
Yes, two things, if you want to improve your answer: 1. It was not immediately clear to me (low IQ, sorry...) that you also have created a second user (appuser). You could emphazise that. 2. The vhost directive PassengerRuby required me to use a a wrapper. Now my entry is /home/redmine/.rvm/wrappers/ruby-2.2.1/ruby. I was hinted to that in the apache error log. FYI: I have set up all on RHEL 6.6, Redmine is now running in version 3.0.3 with Ruby 2.2, Passenger 5.0 and Apache 2.2. My Redmine files are in /var/www/html with user/group redmine:redmine. –  Robert Schneider 2 days ago

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.