Phusion Passenger - HVboom/HowTo-DigitalOcean GitHub Wiki

Description

Easy, Scalable & Reliable Web App Deployment for Ruby, Python, Node.js, Meteor

💬 copied from the home page

Install Phusion Passenger on Ubuntu

Just follow the instruction on PhusionPassenger.com

# Install our PGP key and add HTTPS support for APT
sudo apt-get install -y dirmngr gnupg apt-transport-https ca-certificates curl

curl https://oss-binaries.phusionpassenger.com/auto-software-signing-gpg-key.txt | gpg --dearmor | sudo tee /etc/apt/trusted.gpg.d/phusion.gpg >/dev/null

# Add our APT repository
sudo sh -c 'echo deb https://oss-binaries.phusionpassenger.com/apt/passenger jammy main > /etc/apt/sources.list.d/passenger.list'
sudo apt-get update

# Install Passenger + Apache module
sudo apt-get install -y libapache2-mod-passenger
sudo a2enmod passenger
sudo apache2ctl restart

sudo /usr/bin/passenger-config validate-install
sudo /usr/sbin/passenger-memory-stats

Trouble shooting

Sometimes it could happen, that the new package source for Passenger gets updated and an error occurs, that you need to re-trust the source. In such a case just trigger the installation with an additional option sudo apt-get update --allow-releaseinfo-change.

Install Phusion Passenger on FreeBSD

Important

I do not build Phusion Passenger from the source anymore.

I use the package instead sudo pkg install rubygem-passenger-apache-6.0.18

Setup Apache

Create an Apache configuration file /usr/local/etc/apache24/modules.d/080_mod_passenger.conf:

LoadModule passenger_module /usr/local/lib/ruby/gems/3.1/gems/passenger/buildout/apache2/mod_passenger.so

<IfModule mod_passenger.c>
  # Write a debug file with warnings
  # https://www.phusionpassenger.com/library/config/apache/reference/#logging-and-debugging-options
  # Log level from 0 (crit) - 7 (debug 3)
  PassengerLogLevel 2
  PassengerLogFile /var/log/passenger_debug.log

  # Turn on extended error pages
  # https://www.phusionpassenger.com/library/config/apache/reference/#passengerfriendlyerrorpages
  PassengerFriendlyErrorPages on

  PassengerRoot /usr/local/lib/ruby/gems/3.1/gems/passenger
  # Do not set the default ruby, because otherwise you have to set the ruby version in the vhost too
  # PassengerDefaultRuby /home/passenger/.rvm/gems/ruby-3.1.0@PhusionPassenger/wrappers/ruby
</IfModule>

Runtime checks

Status information

sudo /usr/local/bin/passenger-status

________


Version : 6.0.18
Date    : 2023-11-28 18:51:03 +0100
Instance: thjoMye6 (Apache/2.4.58 (FreeBSD) OpenSSL/1.1.1t-freebsd Phusion_Passenger/6.0.18)

----------- General information -----------
Max pool size : 6
App groups    : 5
Processes     : 5
Requests in top-level queue : 0

----------- Application groups -----------
/home/mario/RubyOnRails/kg (development):
  App root: /home/mario/RubyOnRails/kg
  Requests in queue: 0
  * PID: 96740   Sessions: 0       Processed: 10      Uptime: 1d 7h 26m 12s
    CPU: 0%      Memory  : 180M    Last used: 9h 21

/home/hvkeyguard/RubyOnRails/hvkeyguard (production):
  App root: /home/hvkeyguard/RubyOnRails/hvkeyguard
  Requests in queue: 0
  * PID: 660     Sessions: 0       Processed: 44      Uptime: 1d 5h 7m 39s
    CPU: 0%      Memory  : 127M    Last used: 38m 58

/home/hvdigitalsafe/RubyOnRails/hvdigitalsafe (production):
  App root: /home/hvdigitalsafe/RubyOnRails/hvdigitalsafe
  Requests in queue: 0
  * PID: 3398    Sessions: 0       Processed: 45      Uptime: 1d 3h 35m 43s
    CPU: 0%      Memory  : 87M     Last used: 42m 1

/home/mario/RubyOnRails/HVPlayground (development):
  App root: /home/mario/RubyOnRails/HVPlayground
  Requests in queue: 0
  * PID: 90336   Sessions: 0       Processed: 13      Uptime: 1d 11h 3m 17s
    CPU: 0%      Memory  : 90M     Last used: 9h 21

/home/mario/RubyOnRails/ds (development):
  App root: /home/mario/RubyOnRails/ds
  Requests in queue: 0
  * PID: 94093   Sessions: 0       Processed: 12      Uptime: 1d 8h 53m 26s
    CPU: 0%      Memory  : 121M    Last used: 9h 14

Memory usage

sudo /usr/local/bin/passenger-memory-stats

________


Version: 6.0.18
Date   : 2023-11-28 18:51:47 +0100

---------- Apache processes ----------
PID    PPID   VMSize   Resident  Name
--------------------------------------
8745   90129  40.0 MB  17.2 MB   /usr/local/sbin/httpd -DNOHTTPACCEPT
10236  90129  40.0 MB  17.2 MB   /usr/local/sbin/httpd -DNOHTTPACCEPT
15324  90129  40.0 MB  17.3 MB   /usr/local/sbin/httpd -DNOHTTPACCEPT
15351  90129  40.0 MB  17.2 MB   /usr/local/sbin/httpd -DNOHTTPACCEPT
42369  90129  40.0 MB  17.1 MB   /usr/local/sbin/httpd -DNOHTTPACCEPT
43603  90129  40.0 MB  17.1 MB   /usr/local/sbin/httpd -DNOHTTPACCEPT
46760  90129  40.0 MB  17.1 MB   /usr/local/sbin/httpd -DNOHTTPACCEPT
90129  1      40.0 MB  17.0 MB   /usr/local/sbin/httpd -DNOHTTPACCEPT
90138  90129  40.0 MB  17.3 MB   /usr/local/sbin/httpd -DNOHTTPACCEPT
90140  90129  40.0 MB  17.3 MB   /usr/local/sbin/httpd -DNOHTTPACCEPT
90784  90129  40.0 MB  17.2 MB   /usr/local/sbin/httpd -DNOHTTPACCEPT


-------- Nginx processes ---------



----- Passenger processes ------
PID    VMSize    Resident  Name
--------------------------------
660    227.1 MB  127.4 MB  Passenger RubyApp: /home/hvkeyguard/RubyOnRails/hvkeyguard (production)
3398   179.5 MB  87.8 MB   Passenger RubyApp: /home/hvdigitalsafe/RubyOnRails/hvdigitalsafe (production)
90134  46.4 MB   16.2 MB   PassengerAgent watchdog
90136  353.8 MB  123.7 MB  PassengerAgent core
90336  227.0 MB  91.0 MB   Passenger RubyApp: /home/mario/RubyOnRails/HVPlayground (development)
94093  237.1 MB  121.3 MB  Passenger RubyApp: /home/mario/RubyOnRails/ds (development)
96740  321.2 MB  180.1 MB  Passenger RubyApp: /home/mario/RubyOnRails/kg (development)

Caution

Everything below is outdated!

Setup Phusion Passenger

  • As a precondition you need an up-to-date Ruby and Node.js installation to serve Rails applications.

  • Use a dedicate user to manage the Apache module:

    # -n = <user name>
    # -g = <primary group> (optional) - default: creating a new group with the same name as the user
    # -G = <list of secondary groups> (optional): group _wheel_ allows _sudo_ commands
    # -m = create a home directory
    # -d = <home directory> (optional) - default: /home/<user name>
    # -c = <comment> (optional)
    # -s = <login shell>: must be defined in _/etc/shells_
    # -k = <directory of skeleton dot files>: use _/var/empty_ to not create any dot files
    # -h - = <disable password based login>
    # -w yes = <password is the same as the user name>
    
    # We will start with a user allowed to _sudo_ to install the [[Apache]] module
    sudo pw useradd -n passenger -g www -G wheel -m -k /var/empty -c Rails -s /usr/local/bin/bash -w yes
  • Setup RVM environment: /usr/local/share/bin/setup_rvm

  • Install the passenger gem by creating a specific $HOME/PhusionPassenger/Gemfile

    #ruby=ruby-2.4.0
    #ruby-gemset=PhusionPassenger
    #
    source 'https://rubygems.org'
    
    # Run Rails applications in an Apache web server (see Phusion Passenger homepage https://www.phusionpassenger.com)
    gem 'passenger', '~>5.1'
    • The way RVM is installed ensures, that the gem is automatically installed, if you go into the directory with cd $HOME/PhusionPassenger:

      ...
      > ruby-2.4.0 - #gemset created /home/passenger/.rvm/gems/ruby-2.4.0@PhusionPassenger
      > ruby-2.4.0 - #generating PhusionPassenger wrappers..........
      > installing gem bundler --no-ri --no-rdoc.
      > Fetching gem metadata from https://rubygems.org/..........
      > Fetching version metadata from https://rubygems.org/..
      > Resolving dependencies...
      > Installing rack 2.0.1
      > Installing passenger 5.1.2 with native extensions
      > Bundle complete! 1 Gemfile dependency, 4 gems now installed.
      > Use `bundle show [gemname]` to see where a bundled gem is installed.
  • Create the Apache module (see Phusion Passenger instruction)

    # compile Apache module
    rvmsudo passenger-install-apache2-module  --languages ruby,nodejs
    
    > ...
    
    > --------------------------------------------
    > 
    > Validating installation...
    > 
    >  * Checking whether this Passenger install is in PATH... ✓
    >  * Checking whether there are no other Passenger installations... ✓
    >  * Checking whether Apache is installed... ✓
    >  * Checking whether the Passenger module is correctly configured in Apache... ✓
    > 
    > Everything looks good. :-)
  • Create an Apache configuration file /usr/local/etc/apache24/modules.d/080_mod_passenger.conf:

    LoadModule passenger_module /home/passenger/.rvm/gems/ruby-2.4.0@PhusionPassenger/gems/passenger-5.1.2/buildout/apache2/mod_passenger.so
    <IfModule mod_passenger.c>
      # Write a debug file with warnings
      # https://www.phusionpassenger.com/library/config/apache/reference/#logging-and-debugging-options
      # Log level from 0 (crit) - 7 (debug 3)
      PassengerLogLevel 3
      PassengerLogFile /var/log/passenger_debug.log
    
      # Turn on extended error pages
      # https://www.phusionpassenger.com/library/config/apache/reference/#passengerfriendlyerrorpages
      PassengerFriendlyErrorPages on
    
      PassengerRoot /home/passenger/.rvm/gems/ruby-2.4.0@PhusionPassenger/gems/passenger-5.1.2
      PassengerDefaultRuby /home/passenger/.rvm/gems/ruby-2.4.0@PhusionPassenger/wrappers/ruby
    </IfModule>
  • Test the installation

    rvmsudo passenger-config validate-install
    
    > -------------------------------------------------------------------------
    
    > Checking whether there are multiple Apache installations...
    > Only a single installation detected. This is good.
    
    > -------------------------------------------------------------------------
    
    >  * Checking whether this Passenger install is in PATH... ✓
    >  * Checking whether there are no other Passenger installations... ✓
    >  * Checking whether Apache is installed... ✓
    >  * Checking whether the Passenger module is correctly configured in Apache... ✓
    
    > Everything looks good. :-)
    rvmsudo passenger-memory-stats
    
    > Version: 5.0.29
    > Date   : 2016-05-03 23:21:34 +0200
    
    > ---------- Apache processes -----------
    > PID    PPID   VMSize    Resident  Name
    > ---------------------------------------
    > 69015  1      111.0 MB  0.4 MB    /usr/local/sbin/httpd -DNOHTTPACCEPT
    > 69026  69015  111.0 MB  0.0 MB    /usr/local/sbin/httpd -DNOHTTPACCEPT
    > 69027  69015  111.0 MB  0.1 MB    /usr/local/sbin/httpd -DNOHTTPACCEPT
    > 69028  69015  111.0 MB  0.0 MB    /usr/local/sbin/httpd -DNOHTTPACCEPT
    > 69029  69015  111.0 MB  0.0 MB    /usr/local/sbin/httpd -DNOHTTPACCEPT
    > 69030  69015  111.0 MB  0.0 MB    /usr/local/sbin/httpd -DNOHTTPACCEPT
    
    
    > -------- Nginx processes ---------
    
    
    
    > ----- Passenger processes -----
    > PID    VMSize   Resident  Name
    > -------------------------------
    > 69020  70.2 MB  0.7 MB    PassengerAgent watchdog
    > 69022  70.4 MB  1.6 MB    PassengerAgent core
    > 69024  69.9 MB  0.6 MB    PassengerAgent ust-router

Troubleshooting

Compile / link error

❗ With version 2.0.29 this issue is fixed.

/usr/bin/ld: cannot find -ldl

c++: error: linker command failed with exit code 1 (use -v to see invocation)

rake aborted!

Cause: Passenger 2.0.26 uses the library libev which depends on the ld library not available for FreeBSD (see phusion/passenger#1805)

Solution: Use the GitHub repository with branch stable-5.0: gem 'passenger', github: 'phusion/passenger', branch: 'stable-5.0'

Passenger does not serve Rails applications anymore

Forbidden

You don't have permission to access / on this server.

1st cause

Could not load OpenSSL.

You must recompile Ruby with OpenSSL support or change the sources in your Gemfile from 'https' to 'http'. Instructions for compiling with OpenSSL using RVM are available at http://rvm.io/packages/openssl.

Solution:

cd $HOME/PhusionPassenger && rvm reinstall ruby-2.3.0

2nd cause

Shared object "libkvm.so.6" not found, required by "PassengerAgent"

[Sun Dec 11 19:09:26.203060 2016] [passenger:error] [pid 2487] *** Passenger could not be initialized because of this error: Unable to start the Phusion Passenger watchdog: it seems to have crashed during startup for an unknown reason, with exit code 1

Solution:

Recompile the Apache module again: rvmsudo passenger-install-apache2-module --languages ruby,nodejs

❗ Do not forget to reboot the system, to ensure that the newly compiled version is used.

3rd cause

❗ This issue is fixed with Apache version 2.4.20

Apache 2.4.17 mod_autoindex incompatibility (see phusion/passenger#1642)

Solution:

  1. Edit file /home/freebsd/.rvm/gems/ruby-2.2.1@PhusionPassenger/gems/passenger-5.0.21/src/apache2_module/Hooks.cpp

    1516       // fix for isse #1642 - see https://github.com/phusion/passenger/pull/1642
    1517       // r->handler = "";
    1518       r->handler = "passenger-skip-autoindex";
  2. Recompile passenger-install-apache2-module --languages ruby,nodejs

  3. Adjust file permissions: sudo chmod -R o+X "$HOME/.rvm/gems/ruby-2.2.1@PhusionPassenger"

⚠️ **GitHub.com Fallback** ⚠️