.\" -*- mode: troff; coding: utf-8 -*- .\" Automatically generated by Pod::Man 5.01 (Pod::Simple 3.43) .\" .\" 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 .. .\" \*(C` and \*(C' are quotes in nroff, nothing in troff, for use with C<>. .ie n \{\ . ds C` "" . ds C' "" 'br\} .el\{\ . 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 3pm" .TH Plack::Handler::Apache2 3pm 2024-01-20 "perl v5.38.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 "STARTUP FILE" 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 PSGI application with mod_perl on Apache 2.x. .PP If you want to run PSGI applications \fIbehind\fR Apache instead of using mod_perl, see Plack::Handler::FCGI to run with FastCGI, or use standalone HTTP 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 PSGI 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 PSGI 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 "restart_count" 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 "preload" 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