Nav links

Monday, 17 September 2007

Dynamic publishing in MovableType at NearlyFreeSpeech.NET

My web host, NearlyFreeSpeech.NET, has a rather unusual setup. The web root as seen by a Perl CGI script is very different from that seen by PHP. This leads to a problem in a MovableType-powered blog, which has its administrative web site written in Perl, and its customer-facing site written in PHP (when published dynamically - as a static site it's all HTML). However, it's nothing that a few edits to the source won't fix.

Note that in the code excerpts below I've included the preceding lines to indicate where the code should be placed, in case the line numbers are out. Also, the alterations are based on MovableType v4.01, but other releases of MT4 should be very similar.


  1. File cgi/lib/MT/App/CMS.pm. Here we alter the folder names written into mtview.php, the main dynamic viewing page -



    Line 16687:

    $cgi_path =~ s!/*$!!;

    #Fix Perl -> PHP folder

    $cgi_path =~ s|/home/|/nfsn/content/mySite/|;




    Line 16690:

    my $config = MT->instance->{cfg_file};

    #Fix Perl -> PHP folder

    $config =~ s|/home/|/nfsn/content/mySite/|;




    Note that if you edit these folder names directly in blog/mtview.php then your changes will be overwritten when your site is republished or if you change your publishing settings.




  2. File cgi/php/mt.php. Now another easy part. In here we just need to insert a line in a couple of places to change the folder retrieved from the config file from Perl to PHP form.



    Line 215: (This change might only be needed for SQLite databases)
    $cfg['dbdriver'] = strtolower($driver);



    //Fix Perl -> PHP folder for database

    $cfg['database'] = str_replace("/home/","/nfsn/content/mySite/",$cfg['database']);



    Line 338:


    function configure_paths($blog_site_path) {

    //Fix Perl -> PHP folder for templating

    $blog_site_path = str_replace("/home/","/nfsn/content/mySite/",$blog_site_path);




You might noticed a pattern from my last few blog entries. If you put them together you might get the impression that I've been trying to run a dynamically-published MovableType blog in SQLite3 at NearlyFreeSpeech.NET. Whilst this is true, I found that the end result was unbearably slow, so I've had to remain in the statically-published world.

Update 19 Sep 2007: I have found that enabling the dynamic publishing option Enable Conditional Retrieval speeds up the page display tremendously. The only documentation I've seen on that feature is too sparse for me to understand what it does or why it works so well. In contrast, Enable Dynamic Cache is self-explanatory, but I don't see why it makes no improvement to my site's speed at all. Still, this is good news, and makes dynamic publishing a viable option for me.