Not a developer? Go to MovableType.com

Documentation

Running Movable Type with FastCGI

Movable Type is a large application with a lot of files. In a CGI context that application is loaded into memory every single time, and there is no ability to leverage a cache across a session or multiple requests.

Note: Movable Type 5 is tested with Apache 2.2.x and FastCGI(mod_fcgid) . It is recommend to use FastCGI instead of mod_perl

When using FastCGI, the application is loaded into memory so that it doesn’t have to be reparsed and interpreted every single request. This dramatically increases performance.

It also has the advantage of shielding users of more popular sites from spam attacks. Servers can easily become overwhelmed when the MT App is being loaded simultaneously by so many concurrent processes (presumably someone who is posting comment spam to 10 or 20 entries all at once). By keeping MT in memory posting comments happens a lot quicker so that your web server is not tied up as long…

How to detect if you have FastCGI installed

Many systems for security reasons do not make this information publicly available. Also detecting FastCGI can vary depending upon the implementation of FastCGI that you are using.

Ask your Host

Without a doubt the most reliable way to figure this out is by asking your hosting provider. Many hosting providers will list the modules Apache has installed somewhere in the Knowledge Base or Help section.

Example to install mod_fcgid on CentOS 5.4

Install CPAN modules

You can install required cpan modules by running the command:

# cpan FCGI
# cpan CGI

CGI::Fast is included in CGI module.

Install httpd-devel

# yum install httpd-devel

Install fcgi module

You can download the latest version from http://www.fastcgi.com/.

# wget http://www.fastcgi.com/dist/fcgi-2.4.0.tar.gz
# tar zxvf fcgi-2.4.0.tar.gz -C /usr/local/src
# cd /usr/local/src/fcgi-2.4.0

# ./configure
# make
# make install

Install mod_fcgid

You can download the latest version from http://httpd.apache.org/mod_fcgid/ .

# wget http://ftp.riken.jp/net/apache/httpd/mod_fcgid/mod_fcgid-2.3.5.tar.gz
# tar zxvf mod_fcgid-2.3.5.tar.gz -C /usr/local/src/
# cd /usr/local/src/mod_fcgid-2.3.5/

Install as DSO

# ./configure.apxs
# make
# make install

Configure FastCGI

Create a new configuration file.

# vi /etc/httpd/conf.d/fcgid.conf

Add this configuration.

<IfModule mod_fcgid.c>
  AddHandler fcgid-script .fcgi
  SocketPath /tmp/fcgid_sock/
  IPCConnectTimeout 20
  MaxProcessCount 8
  DefaultMaxClassProcessCount 2
  TerminationScore 10
  SpawnScore 80
  IdleTimeout 300
</IfModule>

Normally “make install” adds LoadModule configuration automatically to the /etc/httpd/conf/httpd.conf. If not, you can add it manually.

 LoadModule fcgid_module /usr/lib/httpd/modules/mod_fcgid.so

How to Run Movable Type under FastCGI

With Movable Type FastCGI support is integrated into the core product. This means that there is no need to install any special files, specifically the MT::Bootstrap file, into Movable Type. However, users will need to make the following changes:

Configuring Movable Type Automatically

If administrators choose, they can setup Apache to run every existing .cgi file via FastCGI. By choosing this approach, there is no need to modify Movable Type at all. To this, you will need to instruct your web server to route all requests to files with an file extension of .cgi through its FastCGI Handler. On an Apache system, that looks like this:

#AddHandler cgi-script .cgi
AddHandler fcgid-script .cgi

Once this is done, Movable Type will immediately be running under FastCGI. Some administrators may not want to make this change globally if other CGI applications on their system are not capable of running under FastCGI. In those circumstance, administrator may want to configure Movable Type manually (see below).

Community contributed note from Su: As an alternative, the htaccess rule can be added directly within the MT directory, where it shouldn’t affect other applications. (Although it could still break plugins/plugin apps if they don’t go through Bootstrap?)

Community contributed note from Delfuego: It’s unclear if this will work perfectly; on my setup, mt-check.cgi doesn’t run at all under FastCGI. The setups below appear to avoid this by not renaming mt-check.cgi to mt-check.fcgi, thereby avoiding it running under FastCGI. I’m still debugging this, but I think that mt-check.cgi might be totally unable to run under FastCGI… A workaround for this that allows the globally-run-CGIs-under-FastCGI solution to function is to manually set the handler for mt-check.cgi back to the normal CGI handler. Given that all the instructions below ONLY set Apache to run a subset of the MT CGIs under FastCGI, the following directives will reset all the other MT CGIs to run under the standard CGI handler:

<Directory /var/www/mt4>
   ...[other config directives]...
   AddHandler fcgid-script .cgi
   <FilesMatch "^mt-(add-notify|atom|check|config|feed|testbg|upgrade|wizard|xmlrpc)\.cgi$">
      SetHandler cgi-script
   </FilesMatch>
</Directory>

Configuring Movable Type Manually

Copy Your CGI files

Make a copy each of the following .cgi scripts, giving each copy a new file extension .fcgi. For example:

# cd /var/www/cgi-bin/mt/
# cp -a mt.cgi mt.fcgi
# cp -a mt-comments.cgi mt-comments.fcgi
# cp -a mt-tb.cgi mt-tb.fcgi
# cp -a mt-ftsearch.cgi mt-ftsearch.fcgi
# cp -a mt-cp.cgi mt-cp.fcgi (Communication Pack Only)

Edit Your MT Configuration

In your Movable Type Configuration File (mt-config.cgi), find the section that contains the lines:

AdminScript mt.cgi
CommentScript mt-comments.cgi
TrackbackScript mt-tb.cgi
SearchScript mt-search.cgi
CommunityScript mt-cp.cgi (Community Pack Only)

And change it to:

AdminScript mt.fcgi
CommentScript mt-comments.fcgi
TrackbackScript mt-tb.fcgi
SearchScript mt-ftsearch.fcgi
CommunityScript mt-cp.fcgi

You will also need to disable LaunchBackgroundTasks in your mt-config.cgi. Set the value of this config parameter to “0” (zero).

GLOB reference error

NOTE: This issue was fixed in Movable Type 5.

Not a GLOB reference at /usr/lib/perl5/FCGI.pm line 125.

If you are experiencing the above error when rebuilding single entries, ensure that the ”’[[LaunchBackgroundTasks]]”’ configuration option is either set to 0 or removed entirely from your ”’mt-config.cgi”’ file.

A way avoiding renaming all those .cgis to .fcgis

I ran into trouble with renaming cgis to fcgis, apache kept going back to the cgi versions and running them the old slow way. So I used apache’s FilesMatch directive to tell it which 5 MT cgis should run under !FastCGI. Here’s an excerpt from my httpd.conf:

<Directory "/var/www/cgi-bin/mt">
    AllowOverride None
    Options None
    Order allow,deny
    Allow from all
<FilesMatch "^mt(?:-(?:comments|search|tb|view))?\.cgi$">
    SetHandler fcgid-script
</FilesMatch>
</Directory>

Permissions Problems?

NOTE: This issue was fixed in Movable Type 5 and mod-fcgid.

After setting up FastCGI and then setting MT up to run under it, I found that my dashboard was telling me that it couldn’t write to the static dashboard directory:

Movable Type was unable to write to its 'support' directory. Please create a
directory at this location: /var/www/mt4/mt-static/support/dashboard/stats/0/000/001,
and assign permissions that will allow the web server write access to it.

Turns out that FastCGI needs special configuration if you run your MT site under Apache and suexec, which I do! FastCGI runs under the web server’s user and group by default; if you want it to use suexec (and all the relevant suexec users and groups defined in your Apache config files), you need to tell it to run under the same security wrapper as Apache. For me, in Ubuntu, I just had to add this config line to my FastCGI Apache configuration file (/etc/apache2/mods-available/fastcgi.conf):

FastCGIWrapper on

After a restart, all was good!

Back

5 Comments

Dave Baker

Dave Baker on October 9, 2007, 8:51 a.m. Reply

“When using mod_perl of FastCGI, the application is loaded into memory so that it doesn’t have to be reparsed and interpreted every single request. This dramatically increases performance.”

Should
modperl of FastCGI
be replaced by
FastCGI
or maybe by
mod
perl or FastCGI
?

P.S. - I am having trouble finding any documentation for modperl, but came across this page when doing a search on modperl using the ‘Search Documentation’ box.

I am getting strange italicization when doing a ‘preview’ of this post —

“perl, but came across this page when doing a search on mod”

is italicized in the preceding paragraph.

I am using Firefox 2.0 (with the latest revision, as of October 9, 2007).

Jay Allen

Jay Allen on January 21, 2008, 5:35 p.m. Reply

Two important possibly time-saving hints when running mod_fcgid:

Dav Yaginuma

Dav Yaginuma on March 25, 2008, 7:41 a.m. Reply

That hello world fcgi doesn’t seem to be right. On my system I had to implement it like this:

#!/usr/bin/perl
# Hello World Script
# Filename: hello.cgi, or hello.fcgi
use FCGI;

while ( FCGI::accept >= 0 ) {
  print "Content-type: text/html\n\n";
  print "Hello world.";
}

Without the while loop, the program exits which is a problem for FastCGI.

You get an error like this in your apache log:

“terminated by calling exit with status 0”

Note that this means you also need to have the perl module FCGI installed. Your server could already be set up for FastCGI, but for another language (say, ruby).

gulliver

gulliver on July 21, 2009, 12:27 p.m. Reply

After various issues with stuff not updating under fcgi, and a ‘why isn’t this mentioned’ response from SA support, I’ve been advised:

===== A restart of the server will be necessary to reload any plugin information after enabling/disabling/deleting.

I don’t believe this is noted specifically in the documentation, but it is the expected behaviour in terms of how FastCGi works (loading information only once).

If you’d like to add this to the documentation, you can do so by adding a comment on the page you’ve noted - it can then be incorporated into the documentation during an update.
ToniMueller

ToniMueller on July 22, 2009, 8:34 a.m. Reply

Head over to O’Reilly, search for “mod_perl”, and pay special attention to all results mentioning Stas Bekman or Lincoln Stein. Good luck!

Leave a Comment