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…
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.
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.
You can install required cpan modules by running the command:
# cpan FCGI # cpan CGI
CGI::Fast is included in CGI module.
# yum install httpd-devel
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
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
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
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:
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>
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)
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).
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.
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
<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>
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):
After a restart, all was good!