.\" -*- 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 "Catalyst::Manual::Deployment::Apache::mod_perl 3pm" .TH Catalyst::Manual::Deployment::Apache::mod_perl 3pm 2024-03-30 "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 Catalyst::Manual::Deployment::Apache::mod_perl \- Deploying Catalyst with mod_perl .SH "mod_perl Deployment" .IX Header "mod_perl Deployment" The recommended method of deploying Catalyst applications is FastCGI. In many cases, mod_perl is not the best solution, but we'll list some pros and cons so you can decide for yourself. .SS Pros .IX Subsection "Pros" \fISpeed\fR .IX Subsection "Speed" .PP mod_perl is fast, and your entire app will be loaded in memory within each Apache process. .PP \fIShared memory for multiple apps\fR .IX Subsection "Shared memory for multiple apps" .PP If you need to run several Catalyst apps on the same server, mod_perl will share the memory for common modules. .SS Cons .IX Subsection "Cons" \fIMemory usage\fR .IX Subsection "Memory usage" .PP Since your application is fully loaded in memory, every Apache process will be rather large. This means a large Apache process will be tied up while serving static files, large files, or dealing with slow clients. For this reason, it is best to run a two-tiered web architecture with a lightweight frontend server passing dynamic requests to a large backend mod_perl server. .PP \fIReloading\fR .IX Subsection "Reloading" .PP Any changes made to the code of your app require a full restart of Apache. Catalyst does not support Apache::Reload or StatINC. This is another good reason to run a frontend web server where you can set up an \&\f(CW\*(C`ErrorDocument 502\*(C'\fR page to report that your app is down for maintenance. .PP Cannot run multiple versions of the same app .IX Subsection "Cannot run multiple versions of the same app" .PP It is not possible to run two different versions of the same application in the same Apache instance because the namespaces will collide. .PP \fICannot run different versions of libraries\fR .IX Subsection "Cannot run different versions of libraries" .PP If you have two different applications which run on the same machine, and each application needs a different versions of a library, the only way to do this is to have per-vhost perl interpreters (with different library paths). This is entirely possible, but nullifies all the memory sharing benefits that you get from having multiple applications sharing the same interpreter. .SH Setup .IX Header "Setup" Now that we have that out of the way, let's talk about setting up mod_perl to run a Catalyst app. .SS "2. Install Apache with mod_perl" .IX Subsection "2. Install Apache with mod_perl" Both Apache 1.3 and Apache 2 are supported, although Apache 2 is highly recommended. With Apache 2, make sure you are using the prefork MPM and not the worker MPM. The reason for this is that many Perl modules are not thread-safe and may have problems running within the threaded worker environment. Catalyst is thread-safe however, so if you know what you're doing, you may be able to run using worker. .PP In Debian, the following commands should get you going. .PP .Vb 2 \& apt\-get install apache2\-mpm\-prefork \& apt\-get install libapache2\-mod\-perl2 .Ve .SS "3. Configure your application" .IX Subsection "3. Configure your application" Every Catalyst application will automagically become a mod_perl handler when run within mod_perl. This makes the configuration extremely easy. Here is a basic Apache 2 configuration. .PP .Vb 2 \& PerlSwitches \-I/var/www/MyApp/lib \& PerlModule MyApp \& \& \& SetHandler modperl \& PerlResponseHandler MyApp \& .Ve .PP The most important line here is \f(CW\*(C`PerlModule MyApp\*(C'\fR. This causes mod_perl to preload your entire application into shared memory, including all of your controller, model, and view classes and configuration. If you have \-Debug mode enabled, you will see the startup output scroll by when you first start Apache. .PP Also, there have been reports that the block above should instead be (but this has not been confirmed): .PP .Vb 4 \& \& use lib \*(Aq/var/www/MyApp/lib\*(Aq; \& use MyApp; \& \& \& \& SetHandler modperl \& PerlResponseHandler MyApp \& .Ve .PP For an example Apache 1.3 configuration, please see the documentation for Catalyst::Engine::Apache::MP13. .SS "Test It" .IX Subsection "Test It" That's it, your app is now a full-fledged mod_perl application! Try it out by going to http://your.server.com/. .SH "Other Options" .IX Header "Other Options" .SS "Non-root location" .IX Subsection "Non-root location" You may not always want to run your app at the root of your server or virtual host. In this case, it's a simple change to run at any non-root location of your choice. .PP .Vb 4 \& \& SetHandler modperl \& PerlResponseHandler MyApp \& .Ve .PP When running this way, it is best to make use of the \f(CW\*(C`uri_for\*(C'\fR method in Catalyst for constructing correct links. .SS "Static file handling" .IX Subsection "Static file handling" Static files can be served directly by Apache for a performance boost. .PP .Vb 4 \& DocumentRoot /var/www/MyApp/root \& \& SetHandler default\-handler \& .Ve .PP This will let all files within root/static be handled directly by Apache. In a two-tiered setup, the frontend server should handle static files. The configuration to do this on the frontend will vary. .PP Note the path of the application needs to be stated explicitly in the web server configuration for this recipes. .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.