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.

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:

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:

Permissions Problems?

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):