MT 3.2 and LightTPD/FastCGI

One of the other exciting features of MT 3.2 is some improvements we made for persistent Perl environments. As such, we are providing some preliminary support for FastCGI. MT 3.2 can now run under LightTPD and FastCGI.

To do this, you'll need to configure your MT LightTPD setup like this (you will need to edit the paths listed below):

fastcgi.server = ( ".fcgi" =>
    ( "localhost" =>
        (
          "socket"   => "/path/to/lighttpd-fcgi.socket",
          "bin-path" => "/path/to/mt/dispatch.fcgi",
          "bin-environment" => ( "PERL5LIB" => "/path/to/mt/lib",
                                 "MT_HOME" => "/path/to/mt",
                                 "MT_CONFIG" => "/path/to/mt-config.cgi" )
        )
    )
  )

You will also need to create the following file named "dispatch.fcgi", placed in your MT directory:

#!/usr/bin/perl -w

use strict;
use MT::Bootstrap;
use CGI::Fast;

# preload app packages
use MT::App::CMS;
use MT::App::Comments;
use MT::App::Trackback;
use MT::App::Search;
## uncomment if necessary, but this adds a lot of
## overhead since it loads up LibXML.
##use MT::AtomServer;


my $handlers = {
    'mt.fcgi' => { class => 'MT::App::CMS', name => 'AdminScript' },
    'mt-comments.fcgi' => { class => 'MT::App::Comments', name => 'CommentScript' },
    'mt-tb.fcgi' => { class => 'MT::App::Trackback', name => 'TrackbackScript' },
    'mt-search.fcgi' => { class => 'MT::App::Search', name => 'SearchScript' },
## See note above about this...
##    'mt-atom.fcgi' => { class => 'MT::AtomServer', name => 'AtomScript' },
};

eval {
    while (my $q = new CGI::Fast) {
        my $cgi = $q->script_name;
        $cgi =~ s!.*/!!;
        my $pkg = $handlers->{$cgi}{class};
        die "Invalid handler for $cgi" unless $pkg;
        my $app = $pkg->new(CGIObject => $q) or die $pkg->errstr;
        local $SIG{__WARN__} = sub { $app->trace($_[0]) };
        $app->init_request(CGIObject => $q) unless $app->{init_request};
        fixup_script_names($app);
        $app->run;
        my $mode = $app->mode || '';
        if ("$pkg->$mode" eq 'MT::App::CMS->plugin_control') {
            exit; # allows server to recycle after changing plugin switches
        }
    }
};
if ($@) {
    print "Content-Type: text/html\n\n";
    print "Got an error: $@";
}

sub fixup_script_names {
    my ($app) = @_;
    $app->config($handlers->{$_}{name}, $_) foreach keys %$handlers;
}

Finally, you will need to create the "stub" .fcgi files (these can be empty, they just have to exist for LightTPD to service the URLs properly): mt.fcgi, mt-comments.fcgi, mt-tb.fcgi, mt-search.fcgi, mt-view.fcgi, mt-atom.fcgi.

Background tasks should be compatible with this configuration as well. I hope you enjoy the performance you'll see from running MT this way.

Note that some third-party plugins may be incompatible with this, since it keeps the MT application and registered plugins in memory from one request to another.

TrackBack

TrackBack URL for this entry:
http://bradchoate.com/mt/feedback/tb/1038

Listed below are links to weblogs that reference MT 3.2 and LightTPD/FastCGI:

» Movable Type 3.2 under LighTPD and FastCGI from ProNet
As we were proud to announce yesterday, Movable Type 3.2 has been released. We'll be providing a lot more details and documentation in the days and weeks to come, but Brad Choate's started the parade of cool new tips and... [Read More]

» links for 2005-08-29 from Quicklinks
MT 3.2 and LightTPD/FastCGI (tags: movies blogging server) The Ruby on Rails Management Advantage (tags: Rails business) PHP powered Movable Type searching (tags: MovableType)... [Read More]

» FastCGI and Movable Type from Jacques Marneweck's Blog
Brad Choate from Six Apart has placed instructions up on his website for running Movable Type using lighthttp and FastCGI.Which in a way is great news as the Movable Type application is going to be flipping fast running via FastCGI... [Read More]

» MT and FastCGI (and Postgres) from David Raynes Personal
Brad put together some instructions for getting Movable Type up and running as a FastCGI application under lighttpd. Unfortunately, it only works for me for a little while. It would appear that, on my site, the database connection is being... [Read More]

» MT 3.2 with FastCGI under Apache from BP's Weblog
Well, Brad Choate explained how to do it for LightTPD, but for those of us with boring old LAMP installs, here's a brief howto for getting MT 3.2 working in FastCGI mode: First, make sure you've got FastCGI support in... [Read More]

» Wordpress on lighttpd from bender
Lighttpd is a cool little webserver that is quickly becoming a serious rival to the reigning champion Apache. Apache is the standard because it can do just about anything you throw at it, and it can do it well. The thing is, it can do way more than I ... [Read More]

» My Movable Type 3.2 Upgrade from Computer Toaster
The upgrade to Movable Type 3.2 on this site’s server wasn’t too rough. Normally wait for x.xx releases but I for once I didn’t have the patience. Scouting about I found Elise Bauer’s A Safe Way to Upgrade to MT... [Read More]

4 Comments

Casey West said:

Brad, I'm using MT under lighttpd and fastcgi and it's mostly great. I've noticed that after some time the application refuses logins, mostly after a time of inactivity. I suspect that the DB handle becomes stale and that disallows authentication using the web interface. I'd like to find a good solution to this problem.

Presently I send a kill signal to my dispatching FastCGI program, which works but is not ideal.

I'm using MT 3.33 with MySQL 4.1.20, lighttpd 1.4.13, and CGI::Fast version 1.05.

Any insight is appreciated.

Reed A. Cartwright said:

I've extended the method mentioned above: here.

Josh said:

Hi Brad,

Can you tell me what is happening if I try to start lighttpd and get the following message?:

Starting Lighttpd
Can't locate FCGI.pm in @INC (@INC contains: /users/home/tubaguy0/web/public/mt/extlib /users/home/tubaguy0/web/public/mt/lib /usr/local/lib/perl5/site_perl/5.8.7/mach /usr/local/lib/perl5/site_perl/5.8.7 /usr/local/lib/perl5/site_perl /usr/local/lib/perl5/5.8.7/BSDPAN /usr/local/lib/perl5/5.8.7/mach /usr/local/lib/perl5/5.8.7 .) at /users/home/tubaguy0/web/public/mt/extlib/CGI/Fast.pm line 22.
BEGIN failed--compilation aborted at /users/home/tubaguy0/web/public/mt/extlib/CGI/Fast.pm line 22.
Compilation failed in require at /users/home/tubaguy0/web/public/mt/dispatch.fcgi line 5.
BEGIN failed--compilation aborted at /users/home/tubaguy0/web/public/mt/dispatch.fcgi line 5.
Can't locate FCGI.pm in @INC (@INC contains: /users/home/tubaguy0/web/public/mt/extlib /users/home/tubaguy0/web/public/mt/lib /usr/local/lib/perl5/site_perl/5.8.7/mach /usr/local/lib/perl5/site_perl/5.8.7 /usr/local/lib/perl5/site_perl /usr/local/lib/perl5/5.8.7/BSDPAN /usr/local/lib/perl5/5.8.7/mach /usr/local/lib/perl5/5.8.7 .) at /users/home/tubaguy0/web/public/mt/extlib/CGI/Fast.pm line 22.
BEGIN failed--compilation aborted at /users/home/tubaguy0/web/public/mt/extlib/CGI/Fast.pm line 22.
Compilation failed in require at /users/home/tubaguy0/web/public/mt/dispatch.fcgi line 5.
BEGIN failed--compilation aborted at /users/home/tubaguy0/web/public/mt/dispatch.fcgi line 5.

I've got my lighttpd.conf file, my dispatch.fcgi and everything else I believe is necessary to have things running, but can't actually start the lighttpd server.

Brad Author Profile Page said:

@Josh: Looks like you're missing the Perl FCGI module. Just install it through the CPAN command:

cpan install FCGI

It requires compilation to install.

About

This article was published on August 26, 2005 10:16 AM.

The article previously posted was Movable Type 3.2!.

The next article is Reboot in progress.

Many more can be found on the home page or by looking through the archives.

Powered by Movable Type