[[user_switching]]
=== User Switching (security feature) ===

ifdef::apache[]
This documentation has moved. Please visit https://www.phusionpassenger.com/library/deploy/apache/user_sandboxing.html
endif::[]
ifdef::nginx[]
This documentation has moved. Please visit https://www.phusionpassenger.com/library/deploy/nginx/user_sandboxing.html
endif::[]
ifdef::standalone[]
This documentation has moved. Please visit https://www.phusionpassenger.com/library/deploy/standalone/user_sandboxing.html
endif::[]

==== Requirements

ifdef::apache[]
This documentation has moved. Please visit https://www.phusionpassenger.com/library/deploy/apache/user_sandboxing.html
endif::[]
ifdef::nginx[]
This documentation has moved. Please visit https://www.phusionpassenger.com/library/deploy/nginx/user_sandboxing.html
endif::[]
ifdef::standalone[]
This documentation has moved. Please visit https://www.phusionpassenger.com/library/deploy/standalone/user_sandboxing.html
endif::[]

==== Effects

ifdef::apache[]
This documentation has moved. Please visit https://www.phusionpassenger.com/library/deploy/apache/user_sandboxing.html
endif::[]
ifdef::nginx[]
This documentation has moved. Please visit https://www.phusionpassenger.com/library/deploy/nginx/user_sandboxing.html
endif::[]
ifdef::standalone[]
This documentation has moved. Please visit https://www.phusionpassenger.com/library/deploy/standalone/user_sandboxing.html
endif::[]

==== Caveats & troubleshooting

ifdef::apache[]
This documentation has moved. Please visit https://www.phusionpassenger.com/library/deploy/apache/user_sandboxing.html
endif::[]
ifdef::nginx[]
This documentation has moved. Please visit https://www.phusionpassenger.com/library/deploy/nginx/user_sandboxing.html
endif::[]
ifdef::standalone[]
This documentation has moved. Please visit https://www.phusionpassenger.com/library/deploy/standalone/user_sandboxing.html
endif::[]

[[user_switching_rpm_caveats]]
==== Red Hat and CentOS caveats

ifdef::apache[]
This documentation has moved. Please visit https://www.phusionpassenger.com/library/deploy/apache/user_sandboxing.html
endif::[]
ifdef::nginx[]
This documentation has moved. Please visit https://www.phusionpassenger.com/library/deploy/nginx/user_sandboxing.html
endif::[]
ifdef::standalone[]
This documentation has moved. Please visit https://www.phusionpassenger.com/library/deploy/standalone/user_sandboxing.html
endif::[]

[[finding_out_app_user]]
==== Finding out what user an application is running as

ifdef::apache[]
This documentation has moved. Please visit https://www.phusionpassenger.com/library/deploy/apache/user_sandboxing.html
endif::[]
ifdef::nginx[]
This documentation has moved. Please visit https://www.phusionpassenger.com/library/deploy/nginx/user_sandboxing.html
endif::[]
ifdef::standalone[]
This documentation has moved. Please visit https://www.phusionpassenger.com/library/deploy/standalone/user_sandboxing.html
endif::[]


[[reducing_memory_usage]]
=== Copy-on-write memory support (reducing memory consumption of Ruby applications) ===

Phusion Passenger automatically leverages operating system virtual memory copy-on-write features in order to reduce the memory usage of Ruby applications. Experience has shown that this reduces memory usage by 33% on average. For this mechanism to work, a Ruby interpreter with a copy-on-write friendly garbage collector is required. The following Ruby interpreters have copy-on-write friendly garbage collectors:

- MRI Ruby >= 2.0. Versions prior to 2.0 did not have a copy-on-write friendly garbage collector.
- http://www.rubyenterpriseedition.com/[Ruby Enterprise Edition], which was Phusion's branch of MRI Ruby 1.8 with a copy-on-write friendly garbage collector and other enhancement. It has reached End-Of-Life as of 2012, but remains available for legacy systems.

[[tuning_sse_websockets]]
=== Tuning for Server Sent Events and WebSockets ===

ifdef::apache[]
This documentation has moved. Please visit https://www.phusionpassenger.com/library/config/apache/tuning_sse_and_websockets.html
endif::[]
ifdef::nginx[]
This documentation has moved. Please visit https://www.phusionpassenger.com/library/config/nginx/tuning_sse_and_websockets.html
endif::[]
ifdef::standalone[]
This documentation has moved. Please visit https://www.phusionpassenger.com/library/config/standalone/tuning_sse_and_websockets.html
endif::[]

[[bundler_support]]
=== Bundler support ===

This documentation has moved. Please visit https://www.phusionpassenger.com/library/indepth/ruby/bundler.html

[[add_passenger_to_gemfile]]
==== Does Phusion Passenger itself need to be added to the Gemfile?

This documentation has moved. Please visit https://www.phusionpassenger.com/library/indepth/ruby/bundler.html#does-passenger-itself-need-to-be-added-to-the-gemfile

=== Installing multiple Ruby on Rails versions ===

Each Ruby on Rails applications that are going to be deployed may require a
specific Ruby on Rails version. You can install a specific version with
this command:
-----------------------------
gem install rails -v X.X.X
-----------------------------
where 'X.X.X' is the version number of Ruby on Rails.

All of these versions will exist in parallel, and will not conflict with each
other. Phusion Passenger will automatically make use of the correct version.

=== Making the application restart after each request ===

In some situations it might be desirable to restart the web application after
each request, for example when developing a non-Rails application that doesn't
support code reloading, or when developing a web framework.

To achieve this, simply create the file 'tmp/always_restart.txt' in your
application's root folder. Unlike 'restart.txt', Phusion Passenger does not
check for this file's timestamp: Phusion Passenger will always restart the
application, as long as 'always_restart.txt' exists.

NOTE: If you're just developing a Rails application then you probably don't need
this feature. If you set
ifdef::apache['RailsEnv development']
ifdef::nginx['rails_env development']
in your web server configuration,
then Rails will automatically reload your application code after each request.
'always_restart.txt' is mostly useful when you're using a web framework that
doesn't support code reloading by itself, of when you're working on a web framework
yourself.

[[sub_uri_deployment_uri_fix]]
=== How to fix broken images/CSS/JavaScript URIs in sub-URI deployments

Some people experience broken images and other broken static assets when they
deploy their application to a sub-URI (i.e. 'http://mysite.com/railsapp/').
The reason for this usually is that you used a
static URI for your image in the views. This means your 'img' source probably refers
to something like '/images/foo.jpg'. The leading slash means that it's an absolute URI:
you're telling the browser to always load 'http://mysite.com/images/foo.jpg' no
matter what. The problem is that the image is actually at
'http://mysite.com/railsapp/images/foo.jpg'. There are two ways to fix this.

The first way (not recommended) is to change your view templates to refer to
'images/foo.jpg'. This is a relative URI: note the lack of a leading slash). What
this does is making the path relative to the current URI. The problem is that if you
use restful URIs, then your images will probably break again when you add a level to
the URI.
For example, when you're at 'http://mysite.com/railsapp' the browser will look for
'http://mysite.com/railsapp/images/foo.jpg'. But when you're at
'http://mysite.com/railsapp/controller'. the browser will look for
'http://mysite.com/railsapp/controller/images/foo.jpg'.
So relative URIs usually don't work well with layout templates.

The second and highly recommended way is to always use Rails helper methods to
output tags for static assets. These helper methods automatically take care
of prepending the base URI that you've deployed the application to. For images
there is `image_tag`, for JavaScript there is `javascript_include_tag` and for
CSS there is `stylesheet_link_tag`. In the above example you would simply remove
the '<img>' HTML tag and replace it with inline Ruby like this:

---------------------------------------
<%= image_tag("foo.jpg") %>
---------------------------------------

This will generate the proper image tag to `$RAILS_ROOT/public/images/foo.jpg`
so that your images will always work no matter what sub-URI you've deployed to.

These helper methods are more valuable than you may think. For example they also
append a timestamp to the URI to better facilitate HTTP caching. For more information,
please refer to
link:http://api.rubyonrails.org/classes/ActionView/Helpers/AssetTagHelper.html[the Rails API docs].

=== Out-of-Band Work and Out-of-Band Garbage Collection

This documentation has moved. Please visit https://www.phusionpassenger.com/library/indepth/ruby/out_of_band_work.html

=== Hooks

This documentation has moved. Please visit https://www.phusionpassenger.com/library/indepth/hooks.html

==== Example

This documentation has moved. Please visit https://www.phusionpassenger.com/library/indepth/hooks.html#example

==== Environment

This documentation has moved. Please visit https://www.phusionpassenger.com/library/indepth/hooks.html#environment

==== Blocking and concurrency

This documentation has moved. Please visit https://www.phusionpassenger.com/library/indepth/hooks.html#blocking-and-concurrency

==== Error handling

This documentation has moved. Please visit https://www.phusionpassenger.com/library/indepth/hooks.html#error-handling

==== Compatibility

This documentation has moved. Please visit https://www.phusionpassenger.com/library/indepth/hooks.html#compatibility

==== Available hooks

This documentation has moved. Please visit https://www.phusionpassenger.com/library/indepth/hooks.html#available-hooks

[[flying_passenger]]
=== Flying Passenger

ifdef::apache[]
This documentation has moved. Please visit https://www.phusionpassenger.com/library/deploy/apache/flying_passenger.html
endif::[]
ifdef::nginx[]
This documentation has moved. Please visit https://www.phusionpassenger.com/library/deploy/nginx/flying_passenger.html
endif::[]
ifdef::standalone[]
This documentation has moved. Please visit https://www.phusionpassenger.com/library/deploy/nginx/flying_passenger.html
endif::[]

==== Requirements

ifdef::apache[]
This documentation has moved. Please visit https://www.phusionpassenger.com/library/deploy/apache/flying_passenger.html
endif::[]
ifdef::nginx[]
This documentation has moved. Please visit https://www.phusionpassenger.com/library/deploy/nginx/flying_passenger.html
endif::[]
ifdef::standalone[]
This documentation has moved. Please visit https://www.phusionpassenger.com/library/deploy/nginx/flying_passenger.html
endif::[]

==== Basic usage

ifdef::apache[]
This documentation has moved. Please visit https://www.phusionpassenger.com/library/deploy/apache/flying_passenger.html
endif::[]
ifdef::nginx[]
This documentation has moved. Please visit https://www.phusionpassenger.com/library/deploy/nginx/flying_passenger.html
endif::[]
ifdef::standalone[]
This documentation has moved. Please visit https://www.phusionpassenger.com/library/deploy/nginx/flying_passenger.html
endif::[]

[[configuring_flying_passenger]]
==== Configuring Flying Passenger

ifdef::apache[]
This documentation has moved. Please visit https://www.phusionpassenger.com/library/deploy/apache/flying_passenger.html
endif::[]
ifdef::nginx[]
This documentation has moved. Please visit https://www.phusionpassenger.com/library/deploy/nginx/flying_passenger.html
endif::[]
ifdef::standalone[]
This documentation has moved. Please visit https://www.phusionpassenger.com/library/deploy/nginx/flying_passenger.html
endif::[]

==== Managing the Flying Passenger daemon

ifdef::apache[]
This documentation has moved. Please visit https://www.phusionpassenger.com/library/deploy/apache/flying_passenger.html
endif::[]
ifdef::nginx[]
This documentation has moved. Please visit https://www.phusionpassenger.com/library/deploy/nginx/flying_passenger.html
endif::[]
ifdef::standalone[]
This documentation has moved. Please visit https://www.phusionpassenger.com/library/deploy/nginx/flying_passenger.html
endif::[]

[[using_flying_passenger_with_mri_18_or_jruby]]
==== Using Flying Passenger with MRI 1.8 or JRuby

ifdef::apache[]
This documentation has moved. Please visit https://www.phusionpassenger.com/library/deploy/apache/flying_passenger.html
endif::[]
ifdef::nginx[]
This documentation has moved. Please visit https://www.phusionpassenger.com/library/deploy/nginx/flying_passenger.html
endif::[]
ifdef::standalone[]
This documentation has moved. Please visit https://www.phusionpassenger.com/library/deploy/nginx/flying_passenger.html
endif::[]

[[flying_passenger_caveats]]
==== Caveats and limitations

ifdef::apache[]
This documentation has moved. Please visit https://www.phusionpassenger.com/library/deploy/apache/flying_passenger.html
endif::[]
ifdef::nginx[]
This documentation has moved. Please visit https://www.phusionpassenger.com/library/deploy/nginx/flying_passenger.html
endif::[]
ifdef::standalone[]
This documentation has moved. Please visit https://www.phusionpassenger.com/library/deploy/nginx/flying_passenger.html
endif::[]
