File: //usr/local/share/man/man3/Plack::Handler::Apache2.3pm
.\" Automatically generated by Pod::Man 4.11 (Pod::Simple 3.35)
.\"
.\" Standard preamble:
.\" ========================================================================
.de Sp \" Vertical space (when we can't use .PP)
.if t .sp .5v
.if n .sp
..
.de Vb \" Begin verbatim text
.ft CW
.nf
.ne \\$1
..
.de Ve \" End verbatim text
.ft R
.fi
..
.\" Set up some character translations and predefined strings. \*(-- will
.\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left
.\" double quote, and \*(R" will give a right double quote. \*(C+ will
.\" give a nicer C++. Capital omega is used to do unbreakable dashes and
.\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff,
.\" nothing in troff, for use with C<>.
.tr \(*W-
.ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p'
.ie n \{\
. ds -- \(*W-
. ds PI pi
. if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch
. if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch
. ds L" ""
. ds R" ""
. ds C` ""
. ds C' ""
'br\}
.el\{\
. ds -- \|\(em\|
. ds PI \(*p
. ds L" ``
. ds R" ''
. ds C`
. ds C'
'br\}
.\"
.\" Escape single quotes in literal strings from groff's Unicode transform.
.ie \n(.g .ds Aq \(aq
.el .ds Aq '
.\"
.\" If the F register is >0, we'll generate index entries on stderr for
.\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index
.\" entries marked with X<> in POD. Of course, you'll have to process the
.\" output yourself in some meaningful fashion.
.\"
.\" Avoid warning from groff about undefined register 'F'.
.de IX
..
.nr rF 0
.if \n(.g .if rF .nr rF 1
.if (\n(rF:(\n(.g==0)) \{\
. if \nF \{\
. de IX
. tm Index:\\$1\t\\n%\t"\\$2"
..
. if !\nF==2 \{\
. nr % 0
. nr F 2
. \}
. \}
.\}
.rr rF
.\" ========================================================================
.\"
.IX Title "Plack::Handler::Apache2 3"
.TH Plack::Handler::Apache2 3 "2020-11-30" "perl v5.26.3" "User Contributed Perl Documentation"
.\" For nroff, turn off justification. Always turn off hyphenation; it makes
.\" way too many mistakes in technical documents.
.if n .ad l
.nh
.SH "NAME"
Plack::Handler::Apache2 \- Apache 2.0 mod_perl handler to run PSGI application
.SH "SYNOPSIS"
.IX Header "SYNOPSIS"
.Vb 6
\& # in your httpd.conf
\& <Location />
\& SetHandler perl\-script
\& PerlResponseHandler Plack::Handler::Apache2
\& PerlSetVar psgi_app /path/to/app.psgi
\& </Location>
\&
\& # Optionally preload your apps in startup
\& PerlPostConfigRequire /etc/httpd/startup.pl
.Ve
.PP
See \*(L"\s-1STARTUP FILE\*(R"\s0 for more details on writing a \f(CW\*(C`startup.pl\*(C'\fR.
.SH "DESCRIPTION"
.IX Header "DESCRIPTION"
This is a mod_perl handler module to run any \s-1PSGI\s0 application with mod_perl on Apache 2.x.
.PP
If you want to run \s-1PSGI\s0 applications \fIbehind\fR Apache instead of using
mod_perl, see Plack::Handler::FCGI to run with FastCGI, or use
standalone \s-1HTTP\s0 servers such as Starman or Starlet proxied with
mod_proxy.
.SH "CREATING CUSTOM HANDLER"
.IX Header "CREATING CUSTOM HANDLER"
If you want to create a custom handler that loads or creates \s-1PSGI\s0
applications using other means than loading from \f(CW\*(C`.psgi\*(C'\fR files, you
can create your own handler class and use \f(CW\*(C`call_app\*(C'\fR class method to
run your application.
.PP
.Vb 2
\& package My::ModPerl::Handler;
\& use Plack::Handler::Apache2;
\&
\& sub get_app {
\& # magic!
\& }
\&
\& sub handler {
\& my $r = shift;
\& my $app = get_app();
\& Plack::Handler::Apache2\->call_app($r, $app);
\& }
.Ve
.SH "STARTUP FILE"
.IX Header "STARTUP FILE"
Here is an example \f(CW\*(C`startup.pl\*(C'\fR to preload \s-1PSGI\s0 applications:
.PP
.Vb 1
\& #!/usr/bin/env perl
\&
\& use strict;
\& use warnings;
\& use Apache2::ServerUtil ();
\&
\& BEGIN {
\& return unless Apache2::ServerUtil::restart_count() > 1;
\&
\& require lib;
\& lib\->import(\*(Aq/path/to/my/perl/libs\*(Aq);
\&
\& require Plack::Handler::Apache2;
\&
\& my @psgis = (\*(Aq/path/to/app1.psgi\*(Aq, \*(Aq/path/to/app2.psgi\*(Aq);
\& foreach my $psgi (@psgis) {
\& Plack::Handler::Apache2\->preload($psgi);
\& }
\& }
\&
\& 1; # file must return true!
.Ve
.PP
See <http://perl.apache.org/docs/2.0/user/handlers/server.html#Startup_File>
for general information on the \f(CW\*(C`startup.pl\*(C'\fR file for preloading perl modules
and your apps.
.PP
Some things to keep in mind when writing this file:
.IP "\(bu" 4
multiple init phases
.Sp
You have to check that \*(L"restart_count\*(R" in Apache2::ServerUtil is \f(CW\*(C`> 1\*(C'\fR,
otherwise your app will load twice and the env vars you set with
PerlSetEnv <http://perl.apache.org/docs/2.0/user/config/config.html#C_PerlSetEnv_>
will not be available when your app is loading the first time.
.Sp
Use the example above as a template.
.IP "\(bu" 4
\&\f(CW@INC\fR
.Sp
The \f(CW\*(C`startup.pl\*(C'\fR file is a good place to add entries to your \f(CW@INC\fR.
Use lib to add entries, they can be in your app or \f(CW\*(C`.psgi\*(C'\fR as well, but if
your modules are in a local::lib or some such, you will need to add the path
for anything to load.
.Sp
Alternately, if you follow the example above, you can use:
.Sp
.Vb 1
\& PerlSetEnv PERL5LIB /some/path
.Ve
.Sp
or
.Sp
.Vb 1
\& PerlSwitches \-I/some/path
.Ve
.Sp
in your \f(CW\*(C`httpd.conf\*(C'\fR, which will also work.
.IP "\(bu" 4
loading errors
.Sp
Any exceptions thrown in your \f(CW\*(C`startup.pl\*(C'\fR will stop Apache from starting at
all.
.Sp
You probably don't want a stray syntax error to bring your whole server down in
a shared or development environment, in which case it's a good idea to wrap the
\&\*(L"preload\*(R" call in an eval, using something like this:
.Sp
.Vb 1
\& require Plack::Handler::Apache2;
\&
\& my @psgis = (\*(Aq/path/to/app1.psgi\*(Aq, \*(Aq/path/to/app2.psgi\*(Aq);
\&
\& foreach my $psgi (@psgis) {
\& eval {
\& Plack::Handler::Apache2\->preload($psgi); 1;
\& } or do {
\& my $error = $@ || \*(AqUnknown Error\*(Aq;
\& # STDERR goes to the error_log
\& print STDERR "Failed to load psgi \*(Aq$psgi\*(Aq: $error\en";
\& };
\& }
.Ve
.IP "\(bu" 4
dynamically loaded modules
.Sp
Some modules load their dependencies at runtime via e.g. Class::Load. These
modules will not get preloaded into your parent process by just including the
app/module you are using.
.Sp
As an optimization, you can dump \f(CW%INC\fR from a request to see if you are using
any such modules and preload them in your \f(CW\*(C`startup.pl\*(C'\fR.
.Sp
Another method is dumping the difference between the \f(CW%INC\fR on
process start and process exit. You can use something like this to
accomplish this:
.Sp
.Vb 1
\& my $start_inc = { %INC };
\&
\& END {
\& my @m;
\& foreach my $m (keys %INC) {
\& push @m, $m unless exists $start_inc\->{$m};
\& }
\&
\& if (@m) {
\& # STDERR goes to the error_log
\& print STDERR "The following modules need to be preloaded:\en";
\& print STDERR "$_\en" for @m;
\& }
\& }
.Ve
.SH "AUTHOR"
.IX Header "AUTHOR"
Tatsuhiko Miyagawa
.SH "CONTRIBUTORS"
.IX Header "CONTRIBUTORS"
Paul Driver
.PP
Ævar Arnfjörð Bjarmason
.PP
Rafael Kitover
.SH "SEE ALSO"
.IX Header "SEE ALSO"
Plack