This blog has been running Movable Type under FastCGI for several months now, first under Apache and later under Lighttpd. During that time have have written my own FCGI server for MT based on Brad Choate’s original code.
Unlike the original, my version creates several worker threads to handle the blog requests and will reap the workers after they served a certain number of requests. This prevents memory leaks from consuming too much system memory (a problem that I have). Also, unlike the original, my version implements a start_background_task subfunction that is compatible with FCGI. Previously, background tasks would fail FCGI MT installs.
Download Links: The FCGI Server: mt-dispatch (source) The FreeBSD rc.d script: mt-dispatch.sh (source)
Instructions on installing are below the fold.
Installation Instructions
These instructions are for a FreeBSD 6.1 install with Lighttpd. After downloading the FCGI server and the rc.d script issue the following commands as root.
cp mt-dispatch /usr/local/bin/mt-dispatch chown root:wheel /usr/local/bin/mt-dispatch chmod 555 /usr/local/bin/mt-dispatch cp mt-dispatch.sh /usr/local/etc/rc.d/mt-dispatch chown root:wheel /usr/local/etc/rc.d/mt-dispatch chmod 555 /usr/local/etc/rc.d/mt-dispatch mkdir /var/run/www chown www:www /var/run/www
Install the needed perl modules if you don’t have them: FCGI, FCGI::ProcManager, CGI::Fast, and Sub::Override.
Next go to mt-config.cgi in your MT directory and add/edit the following lines.
AdminScript mt.fcgi CommentScript mt-comments.fcgi TrackbackScript mt-tb.fcgi SearchScript mt-search.fcgi AtomScript mt-atom.fcgi
Then create the following files in the MT directory. They can be empty. The webserver can also be configured so that this is unnecessary.
touch mt.fcgi touch mt-comment.fcgi touch mt-tb.fcgi touch mt-search.fcgi touch mt-atom.fcgi
You may also want to rename the corresponding .cgi script to prevent robots and spammers from still accessing them.
Then edit ‘/etc/rc.conf’ to enable the dispatcher.
mt_dispatch_enable = "YES" mt_dispatch_socket="/tmp/mt-dispatch.sock" mt_dispatch_children="2" mt_dispatch_max_requests="100" mt_dispatch_home="/usr/local/www/cgi-bin/mt"
The default settings used by the rc.d script are as follows
mt_dispatch_enable="NO" mt_dispatch_children="2" mt_dispatch_max_requests="100" mt_dispatch_socket="/tmp/mt-dispatch.sock" mt_dispatch_addr="localhost" mt_dispatch_home="/usr/local/www/cgi-bin/mt" mt_dispatch_port="8003" mt_dispatch_bin_path="/usr/local/bin/mt-dispatch" mt_dispatch_user="www" mt_dispatch_group="www" mt_dispatch_pidfile="/var/run/www/mt-dispatch.pid" mt_dispatch_env="SHELL PATH USER" mt_dispatch_perl5lib=""
Note that if socket is not empty, then it will override the port specification. You can then start, restart, etc. the MT fcgi server independently of the webserver.
/usr/local/etc/rc.d/mt-dispatch start
Next edit /etc/lighttpd.conf and add the following lines, changing them as needed.
alias.url += ( "/cgi-bin" => "/usr/local/www/cgi-bin")
$HTTP["url"] =~ "^/cgi-bin/mt" {
cgi.assign = ( ".cgi" => "" )
fastcgi.server += ( ".fcgi" => ((
"socket" => "/tmp/mt-dispatch.sock",
)))
}
else $HTTP["url"] =~ "^/cgi-bin" {
cgi.assign = ( "" => "" )
}
Now just restart lighty and you are ready serve MT under fcgi.


I was made aware that the memory leak that I was having was fixed in MT 3.3. Now the worker threads can serve many more requests without killing the system. I’ve set the number on this server to 10000.
thanks for sharing
thanks for sharing
Update