.\" Automatically generated by Pod::Man 2.25 (Pod::Simple 3.26) .\" .\" 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" '' '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 turned on, 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. .ie \nF \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . nr % 0 . rr F .\} .el \{\ . de IX .. .\} .\" .\" Accent mark definitions (@(#)ms.acc 1.5 88/02/08 SMI; from UCB 4.2). .\" Fear. Run. Save yourself. No user-serviceable parts. . \" fudge factors for nroff and troff .if n \{\ . ds #H 0 . ds #V .8m . ds #F .3m . ds #[ \f1 . ds #] \fP .\} .if t \{\ . ds #H ((1u-(\\\\n(.fu%2u))*.13m) . ds #V .6m . ds #F 0 . ds #[ \& . ds #] \& .\} . \" simple accents for nroff and troff .if n \{\ . ds ' \& . ds ` \& . ds ^ \& . ds , \& . ds ~ ~ . ds / .\} .if t \{\ . ds ' \\k:\h'-(\\n(.wu*8/10-\*(#H)'\'\h"|\\n:u" . ds ` \\k:\h'-(\\n(.wu*8/10-\*(#H)'\`\h'|\\n:u' . ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'^\h'|\\n:u' . ds , \\k:\h'-(\\n(.wu*8/10)',\h'|\\n:u' . ds ~ \\k:\h'-(\\n(.wu-\*(#H-.1m)'~\h'|\\n:u' . ds / \\k:\h'-(\\n(.wu*8/10-\*(#H)'\z\(sl\h'|\\n:u' .\} . \" troff and (daisy-wheel) nroff accents .ds : \\k:\h'-(\\n(.wu*8/10-\*(#H+.1m+\*(#F)'\v'-\*(#V'\z.\h'.2m+\*(#F'.\h'|\\n:u'\v'\*(#V' .ds 8 \h'\*(#H'\(*b\h'-\*(#H' .ds o \\k:\h'-(\\n(.wu+\w'\(de'u-\*(#H)/2u'\v'-.3n'\*(#[\z\(de\v'.3n'\h'|\\n:u'\*(#] .ds d- \h'\*(#H'\(pd\h'-\w'~'u'\v'-.25m'\f2\(hy\fP\v'.25m'\h'-\*(#H' .ds D- D\\k:\h'-\w'D'u'\v'-.11m'\z\(hy\v'.11m'\h'|\\n:u' .ds th \*(#[\v'.3m'\s+1I\s-1\v'-.3m'\h'-(\w'I'u*2/3)'\s-1o\s+1\*(#] .ds Th \*(#[\s+2I\s-2\h'-\w'I'u*3/5'\v'-.3m'o\v'.3m'\*(#] .ds ae a\h'-(\w'a'u*4/10)'e .ds Ae A\h'-(\w'A'u*4/10)'E . \" corrections for vroff .if v .ds ~ \\k:\h'-(\\n(.wu*9/10-\*(#H)'\s-2\u~\d\s+2\h'|\\n:u' .if v .ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'\v'-.4m'^\v'.4m'\h'|\\n:u' . \" for low resolution devices (crt and lpr) .if \n(.H>23 .if \n(.V>19 \ \{\ . ds : e . ds 8 ss . ds o a . ds d- d\h'-1'\(ga . ds D- D\h'-1'\(hy . ds th \o'bp' . ds Th \o'LP' . ds ae ae . ds Ae AE .\} .rm #[ #] #H #V #F C .\" ======================================================================== .\" .IX Title "Plack::Handler::Apache2 3pm" .TH Plack::Handler::Apache2 3pm "2014-04-05" "perl v5.14.2" "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 \& \& SetHandler perl\-script \& PerlResponseHandler Plack::Handler::Apache2 \& PerlSetVar psgi_app /path/to/app.psgi \& \& \& # Optionally preload your apps in startup \& PerlPostConfigRequire /etc/httpd/startup.pl .Ve .PP See \*(L"\s-1STARTUP\s0 \s-1FILE\s0\*(R" 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 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 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 \&\*(Aevar Arnfjo\*:r\*(d- Bjarmason .PP Rafael Kitover .SH "SEE ALSO" .IX Header "SEE ALSO" Plack