Not a developer? Go to MovableType.com

Documentation

Running Movable Type under mod_perl

Mod_perl is an Apache Web Server module that creates a stateful and persistent application environment for Perl based web applications. The module works by loading the Perl interpreter into Apache’s memory so that the cost of loading the interpreter is incurred only once. This is in contrast to how normal CGI is handled, which loads the perl interpreter for each request.

Warning: Movable Type 5 is tested with FastCGI(mod_fcgid) . It is recommend to use FastCGI instead of mod_perl

Why use mod_perl?

Using this module can result in dramatic performance improvements for Movable Type.

Setting Up Movable Type and mod_perl

mod_perl embeds a Perl interpreter into the Apache server, so that dynamic content produced by Perl scripts can be served in response to incoming requests, without the significant overhead of re-launching the Perl interpreter for each request.

Movable Type can run under modperl 1.x in either Registry mode or as a set of full-fledged handlers. Note that in order to run under *modperl, you must have Apache::Request and Apache::Cookie installed; these modules comprise the *libapreq distribution, which can be downloaded from CPAN.

Setting up MT under Registry is just like setting up any other CGI script under Registry; add the following to your httpd.conf:

PerlModule Apache::Registry
<Location /path/to/mt>
SetHandler perl-script
PerlHandler Apache::Registry
Options +ExecCGI
</Location>

You will need to host your mt-static files in another directory outside of /path/to/mt, just as if you had placed MT into the cgi-bin.

If you want even more speed, consider running Movable Type to run as a mod_perl handler. You will need to set up a handler for the main application and one for each of your public scripts.

  1. Set up your mt-static directory in a web-accessible path not under /mt/.
  2. Add the following to your httpd.conf:

    <Perl>
    use lib </path/to/mt/lib>;
    use lib </path/to/mt/extlib>;
    </Perl>
    
    
    PerlModule MT::App::CMS
    <Location /mt/app>
    SetHandler perl-script
    PerlHandler MT::App::CMS
    PerlSetVar MTConfig /path/to/mt-config.cgi
    </Location>
    
    
    PerlModule MT::App::Comments
    <Location /mt/comments>
    SetHandler perl-script
    PerlHandler MT::App::Comments
    PerlSetVar MTConfig /path/to/mt-config.cgi
    </Location>
    
    
    PerlModule MT::App::Trackback
    <Location /mt/trackback>
    SetHandler perl-script
    PerlHandler MT::App::Trackback
    PerlSetVar MTConfig /path/to/mt-config.cgi
    </Location>
    
    
    PerlModule MT::App::Search
    <Location /mt/search>
    SetHandler perl-script
    PerlHandler MT::App::Search
    PerlSetVar MTConfig /path/to/mt-config.cgi
    </Location>
    
    
    PerlModule Apache::XMLRPC::Lite
    PerlModule MT::XMLRPCServer
    <Location /mt/xmlrpc>
    SetHandler perl-script
    PerlHandler Apache::XMLRPC::Lite
    PerlSetVar dispatch_to &quot;blogger, metaWeblog, mt&quot;
    PerlSetVar MTConfig /path/to/mt-config.cgi
    </Location>
    

    Note that, as an alternative to the use lib statement above, you could also use:

    PerlSetEnv PERL5LIB /path/to/mt/lib
    
  3. In your mt-config.cgi file, you will need to use the following settings:

    CGIPath http://my.server.com/mt/
    StaticWebPath /mt-static/
    AdminScript app
    CommentScript comments
    TrackbackScript trackback
    SearchScript search
    XMLRPCScript xmlrpc
    

    StaticWebPath should correspond to the URI you set when setting up your mt-static directory in Step 1.

    If you are using BerkeleyDB, you also need to add the following in addition to the lines above:

    DataSource /path/to/db</code></pre>
    
Back

1 Comment

Nei on January 25, 2010, 12:52 a.m. Reply

There is a bug in Movable Type 5.01’s MT.pm which prevents from passing the MTHome and MTConfig variables to be passed to the instance during bootstrap.

Here is the fix, which can be applied using patch:

diff -pru lib/MT.pm lib/MT.pm
--- lib/MT.pm   2009-12-25 02:51:20.000000000 +0100
+++ lib/MT.pm   2010-01-25 09:39:42.000000000 +0100
@@ -1001,6 +1001,9 @@ sub log_times {
         if ($ENV{MOD_PERL}) {
             print PERFLOG "# App Mode: mod_perl\n";
         }
+        elsif ($ENV{MOD_PERL_API_VERSION}) {
+            print PERFLOG "# App Mode: mod_perl$ENV{MOD_PERL_API_VERSION}\n";
+        }
         elsif ($ENV{FAST_CGI}) {
             print PERFLOG "# App Mode: FastCGI\n";
         }
@@ -1075,8 +1078,8 @@ sub init_config_from_db {

 sub bootstrap {
     my $pkg = shift;
-    $pkg->init_paths() or return;
-    $pkg->init_core()  or return;
+    $pkg->init_paths({@_}) or return;
+    $pkg->init_core(@_)  or return;
 }

 sub init_paths {
@@ -1195,7 +1198,7 @@ sub init {
     my $mt    = shift;
     my %param = @_;

-    $mt->bootstrap() unless $MT_DIR;
+    $mt->bootstrap(@_) unless $MT_DIR;
     $mt->{mt_dir}     = $MT_DIR;
     $mt->{config_dir} = $CFG_DIR;
     $mt->{app_dir}    = $APP_DIR;

Contrary to the Note in System Requirements, Movable Type even runs fine under mod_perl2 as a handler if you add the mod_perl2 : method attribute to the ($$) prototype of the handler declaration and use the CGI-layer instead of native (mod_perl1) calls. Only the Cache driver bails because it checks for mod_perl before mod_perl2. Easy to patch though:

diff -pru extlib/Data/ObjectDriver/Driver/Cache/Apache.pm extlib/Data/ObjectDriver/Driver/Cache/Apache.pm
--- extlib/Data/ObjectDriver/Driver/Cache/Apache.pm  2009-12-07 10:58:19.000000000 +0100
+++ extlib/Data/ObjectDriver/Driver/Cache/Apache.pm  2010-01-25 09:39:42.000000000 +0100
@@ -15,10 +15,10 @@ sub init {

 sub r {
     my $driver = shift;
-    if ($INC{"mod_perl.pm"}) {
-        return Apache->request;
-    } elsif ($INC{"mod_perl2.pm"}) {
+    if ($INC{"mod_perl2.pm"}) {
         return Apache2::RequestUtil->request;
+    } elsif ($INC{"mod_perl.pm"}) {
+        return Apache->request;
     } else {
         die "Not running on mod_perl environment.";
     }

Have fun!