Packaging

Introduction

This document describes how packagers can package Phusion Passenger binaries for their operating system.

Phusion Passenger can be configured in 2 ways, the "originally packaged" configuration where everything is in the same directory, and the "natively packaged" configuration where files are scattered across the filesystem, e.g. in a FHS-compliant configuration. This document describes how you can configure Phusion Passenger to locate its own files when they're scattered across the filesystem.

Phusion Passenger files are also called assets in this document.

Originally packaged

This is the configuration you get when you checkout Phusion Passenger from git, when you install Phusion Passenger from a gem or when you extract it from a tarball. All the original files are stored in a single directory tree, which we call the source root.

The git repository, gems and tarballs do not come with any binaries; they have to be compiled by the user. Phusion Passenger looks for binaries in, and (if the user initiates the compilation process) stores binaries in, the following directories:

Natively packaged

Phusion Passenger is packaged, usually (but not necessarily) through a DEB or RPM package. This configuration comes not only with all necessary binaries, but also with some (but not all) source files. This is because when you run Phusion Passenger with a different Ruby interpreter than the packager intended, Phusion Passenger must be able to compile a new Ruby extension for that Ruby interpreter. This configuration does not however allow compiling against a different Apache version than the packager intended (but does allow compiling against a different Nginx version).

In this configuration, files can be scattered anywhere throughout the filesystem. This way Phusion Passenger can be packaged in an FHS-compliant way. The exact locations of the different types of files can be specified through a location configuration file. The existance and usage of a location configuration file does not automatically imply that Phusion Passenger is natively packaged.

If Phusion Passenger needs to have a new Ruby extension compiled, then it will store that in ~/.passenger/native_support/<VERSION>/<ARCH>.

The location configuration file

The Phusion Passenger administration tools, such as passenger-status, look for a location configuration file in the following places, in the given order:

If it cannot find a location configuration file, then it assumes that Phusion Passenger is originally packaged. If a location configuration file is found then the configuration is determined by the natively_packaged option in the location configuration file, which can be either "true" or "false".

The Apache module and the Nginx module expect PassengerRoot/passenger_root to refer to either a directory or a file. If the value refers to a directory, then it assumes that Phusion Passenger is originally packaged, where the source root is the specified directory. If the value refers to a file, then it will use it as the location configuration file, and the configuration depends on the natively_packaged setting.

The location configuration file is an ini file that looks as follows:

[locations]
natively_packaged=true
bin_dir=/usr/bin
agents_dir=/usr/lib/phusion-passenger/agents
lib_dir=/usr/lib/phusion-passenger
helper_scripts_dir=/usr/share/phusion-passenger/helper-scripts
resources_dir=/usr/share/phusion-passenger
include_dir=/usr/share/phusion-passenger/include
doc_dir=/usr/share/doc/phusion-passenger
ruby_libdir=/usr/lib/ruby/vendor_ruby
apache2_module_path=/usr/lib/apache2/modules/mod_passenger.so
ruby_extension_source_dir=/usr/share/phusion-passenger/ruby_extension_source
nginx_module_source_dir=/usr/share/phusion-passenger/ngx_http_passenger_module

All keys except fo natively_packaged specify the locations of assets and asset directories. The "Asset types" section provides a description of all asset types.

Thus, if you're packaging Phusion Passenger, then we recommend the following:

The Phusion Passenger Ruby libraries

phusion_passenger.rb

The Phusion Passenger administration tools are written in Ruby. So the first thing they do is trying to load phusion_passenger.rb, which is the source file responsible for figuring out where all the other Phusion Passenger files are. It tries to look for phusionpassenger.rb in <OWN_DIRECTORY>/../lib where <OWN_DIRECTORY> is the directory that the tool is located in. If phusionpassenger.rb is not there, then it tries to load it from the normal Ruby load path.

Ruby extension

The Phusion Passenger loader scripts try to load the Phusion Passenger Ruby extension (passenger_native_support.so) from the following places, in the given order:

If it cannot find the Ruby extension in any of the above places, then it will attempt to compile the Ruby extension and store it in ~/.passenger/native_support/<VERSION>/<ARCH>.

Conclusion for packagers

If you're packaging Phusion Passenger then you should put both phusion_passenger.rb and passenger_native_support.so somewhere in the Ruby load path, or make sure that that directory is included in the $RUBYLIB environment variable. You cannot specify a custom directory though the location configuration file.

Asset types

Throughout the Phusion Passenger codebase, we refer to all kinds of assets. Here's a list of all possible assets and asset directories.

Vendoring of libraries

Phusion Passenger vendors libev and libeio in order to make installation easier for users on operating systems without proper package management, like OS X. If you want Phusion Passenger to compile against the system-provided libev and/or libeio instead, then set the following environment variables before compiling:

Note that we require at least libev 4.11 and libeio 1.0.

Generating gem and tarball

Use the following commands to generate a gem and tarball, in which Phusion Passenger is originally packaged and without any binaries:

rake package:gem
rake package:tarball

The files will be stored in pkg/.

Fakeroot

You can generate a fakeroot with the command rake fakeroot. This will generate an FHS-compliant directory tree in pkg/fakeroot, which you can directly package or with minor modifications. The fakeroot even contains a location configuration file.