.\" 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 "Catalyst::Manual::Deployment::Apache::FastCGI 3pm"
.TH Catalyst::Manual::Deployment::Apache::FastCGI 3pm "2020-07-25" "perl v5.30.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"
Catalyst::Manual::Deployment::Apache::FastCGI \- Deploying Catalyst with FastCGI on Apache
.SS "Setup"
.IX Subsection "Setup"
\fI1. Install Apache with mod_fastcgi\fR
.IX Subsection "1. Install Apache with mod_fastcgi"
.PP
mod_fastcgi for Apache is a third-party module, and can be found at
. It is also packaged in many distributions
(for example, libapache2\-mod\-fastcgi in Debian). You will also need to
install the \s-1FCGI\s0 module from \s-1CPAN.\s0
.PP
Important Note! If you experience difficulty properly rendering pages,
try disabling Apache's mod_deflate (Deflate Module), e.g. 'a2dismod deflate'.
.SS "Apache 1.x, 2.x"
.IX Subsection "Apache 1.x, 2.x"
Apache requires the mod_fastcgi module. The same module supports both
Apache 1 and 2.
.PP
There are three ways to run your application under FastCGI on Apache: server,
static, and dynamic.
.PP
\fIStandalone server mode\fR
.IX Subsection "Standalone server mode"
.PP
.Vb 2
\& FastCgiExternalServer /tmp/myapp.fcgi \-socket /tmp/myapp.socket
\& Alias /myapp/ /tmp/myapp.fcgi/
\&
\& # Or, run at the root
\& Alias / /tmp/myapp.fcgi/
\&
\& # Optionally, rewrite the path when accessed without a trailing slash
\& RewriteRule ^/myapp$ myapp/ [R]
.Ve
.PP
The FastCgiExternalServer directive tells Apache that when serving
/tmp/myapp to use the FastCGI application listening on the socket
/tmp/mapp.socket. Note that /tmp/myapp.fcgi \fB\s-1MUST NOT\s0\fR exist \*(--
it's a virtual file name. With some versions of \f(CW\*(C`mod_fastcgi\*(C'\fR or
\&\f(CW\*(C`mod_fcgid\*(C'\fR, you can use any name you like, but some require that the
virtual filename end in \f(CW\*(C`.fcgi\*(C'\fR.
.PP
It's likely that Apache is not configured to serve files in /tmp, so the
Alias directive maps the url path /myapp/ to the (virtual) file that runs the
FastCGI application. The trailing slashes are important as their use will
correctly set the \s-1PATH_INFO\s0 environment variable used by Catalyst to
determine the request path. If you would like to be able to access your app
without a trailing slash (http://server/myapp), you can use the above
RewriteRule directive.
.PP
\fIStatic mode\fR
.IX Subsection "Static mode"
.PP
The term 'static' is misleading, but in static mode Apache uses its own
FastCGI Process Manager to start the application processes. This happens at
Apache startup time. In this case you do not run your application's
fastcgi.pl script \*(-- that is done by Apache. Apache then maps URIs to the
FastCGI script to run your application.
.PP
.Vb 2
\& FastCgiServer /path/to/myapp/script/myapp_fastcgi.pl \-processes 3
\& Alias /myapp/ /path/to/myapp/script/myapp_fastcgi.pl/
.Ve
.PP
FastCgiServer tells Apache to start three processes of your application at
startup. The Alias command maps a path to the FastCGI application. Again,
the trailing slashes are important.
.PP
\fIDynamic mode\fR
.IX Subsection "Dynamic mode"
.PP
In FastCGI dynamic mode, Apache will run your application on demand,
typically by requesting a file with a specific extension (e.g. .fcgi). ISPs
often use this type of setup to provide FastCGI support to many customers.
.PP
In this mode it is often enough to place or link your *_fastcgi.pl script in
your cgi-bin directory with the extension of .fcgi. In dynamic mode Apache
must be able to run your application as a \s-1CGI\s0 script so ExecCGI must be
enabled for the directory.
.PP
.Vb 1
\& AddHandler fastcgi\-script .fcgi
.Ve
.PP
The above tells Apache to run any .fcgi file as a FastCGI application.
.PP
Here is a complete example:
.PP
.Vb 3
\&
\& ServerName www.myapp.com
\& DocumentRoot /path/to/MyApp
\&
\& # Allow CGI script to run
\&
\& Options +ExecCGI
\&
\&
\& # Tell Apache this is a FastCGI application
\&
\& SetHandler fastcgi\-script
\&
\&
.Ve
.PP
Then a request for /script/myapp_fastcgi.pl will run the
application.
.PP
For more information on using FastCGI under Apache, visit
.PP
\fIAuthorization header with mod_fastcgi or mod_cgi\fR
.IX Subsection "Authorization header with mod_fastcgi or mod_cgi"
.PP
By default, mod_fastcgi/mod_cgi do not pass along the Authorization header,
so modules like Catalyst::Plugin::Authentication::Credential::HTTP will
not work. To enable pass-through of this header, add the following
mod_rewrite directives:
.PP
.Vb 2
\& RewriteCond %{HTTP:Authorization} ^(.+)
\& RewriteRule ^(.*)$ $1 [E=HTTP_AUTHORIZATION:%1,PT]
.Ve
.PP
2. Configure your application
.IX Subsection "2. Configure your application"
.PP
.Vb 3
\& # Serve static content directly
\& DocumentRoot /var/www/MyApp/root
\& Alias /static /var/www/MyApp/root/static
\&
\& FastCgiServer /var/www/MyApp/script/myapp_fastcgi.pl \-processes 3
\& Alias /myapp/ /var/www/MyApp/script/myapp_fastcgi.pl/
\&
\& # Or, run at the root
\& Alias / /var/www/MyApp/script/myapp_fastcgi.pl/
.Ve
.PP
The above commands will launch 3 app processes and make the app available at
/myapp/
.PP
\fIStandalone server mode\fR
.IX Subsection "Standalone server mode"
.PP
While not as easy as the previous method, running your app as an external
server gives you much more flexibility.
.PP
First, launch your app as a standalone server listening on a socket.
.PP
.Vb 1
\& script/myapp_fastcgi.pl \-l /tmp/myapp.socket \-n 5 \-p /tmp/myapp.pid \-d
.Ve
.PP
You can also listen on a \s-1TCP\s0 port if your web server is not on the same
machine.
.PP
.Vb 1
\& script/myapp_fastcgi.pl \-l :8080 \-n 5 \-p /tmp/myapp.pid \-d
.Ve
.PP
You will probably want to write an init script to handle starting/stopping
of the app using the pid file.
.PP
Now, we simply configure Apache to connect to the running server.
.PP
.Vb 5
\& # 502 is a Bad Gateway error, and will occur if the backend server is down
\& # This allows us to display a friendly static page that says "down for
\& # maintenance"
\& Alias /_errors /var/www/MyApp/root/error\-pages
\& ErrorDocument 502 /_errors/502.html
\&
\& FastCgiExternalServer /tmp/myapp.fcgi \-socket /tmp/myapp.socket
\& Alias /myapp/ /tmp/myapp.fcgi/
\&
\& # Or, run at the root
\& Alias / /tmp/myapp.fcgi/
.Ve
.PP
\fIMore Info\fR
.IX Subsection "More Info"
.PP
Catalyst::Manual::Deployment::FastCGI.
.SH "AUTHORS"
.IX Header "AUTHORS"
Catalyst Contributors, see Catalyst.pm
.SH "COPYRIGHT"
.IX Header "COPYRIGHT"
This library is free software. You can redistribute it and/or modify it under
the same terms as Perl itself.