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.
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.
I've extended the method mentioned above: here.
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.
@Josh: Looks like you're missing the Perl FCGI module. Just install it through the CPAN command:
cpan install FCGIIt requires compilation to install.