The Movable Type User Manual

NOTE: This documentation is for Movable Type 3.2. If you are using a newer version, please see the documentation for Movable type 3.3x or Movable Type Enterprise.

« 5: Categories | Up | 7: Comments »

Chapter 6: Publishing

In this section:


While entries make up the content of a weblog and templates control how these entries are displayed, it is the process of publishing that makes a weblog go. Movable Type refers to the process of publishing as rebuilding -- a reference to its static page generation roots. When a rebuild is performed, templates and your content are merged to publish a page that visitors can view in their browsers.

Choosing Between a Static or Dynamic Publishing Model

Movable Type provides the flexibility to choose between either static page generation or dynamic pages to optimize weblog performance on a per-template basis.

The static page publishing model provides a number of important advantages. Static pages are significantly more scalable and less resource intensive, once created. This model offers a great deal of flexibility when working with dynamic page generation technologies, allowing you to easily publish content to multiple or remote locations with standard sychronization tools. Until MT version 3.1, static page generation was the only publishing option in MT and remains the default even now.

The dynamic publishing model provides the advantage of immediacy. Rebuild times are significantly shorter and template changes are immediately reflected in the layout since pages are generated when requested. Disk space requirements are reduced since content pages are generated in memory rather than being read from the file system. The dynamic publishing engine is implemented on top of PHP and the Smarty Template Engine; and requires that you be using a SQL database (i.e. MySQL, SQLite or PostgreSQL) for your Movable Type installation.

With the flexibility to choose your publishing model, you can maintain the best balance of fast rebuilds and low server load to suit your needs. Which is best and most efficient depends on your individual situation.

Problem

You want to republish some of a weblog's content.

Solution

Click the Rebuild Site button in the Weblog Toolbar and select the appropriate rebuild process.

Discussion

When you make changes that affect the display of your weblog, involving areas such as templates, category labels and so on, you will need to rebuild your pages to see these changes reflected on your public site. Rebuilding is the process of merging templates with weblog content to publish pages that visitors can view in their browsers.

When you need to rebuild, click the Rebuild Site button in the Weblog Toolbar. A pop-up window will open giving you the choice of either rebuilding your entire site or only one of your archive types. Select the rebuild option which best suits the changes you have made to your content, and press the Rebuild button. Rebuilding pages for a specific archive type is naturally faster than rebuilding your entire site.

Rebuilding a site can take a fair amount of time depending on the quantity of content in each weblog and the number of archive options in use. Please be patient, and do not abort the rebuilding process.

When editing or creating an entry you needn't do a rebuild of your pages. Changes to entries marked "Publish" will automatically rebuild the archives for that entry and all of the indexes.

Timeout and configuration parameter here?

Problem

You want to enable the dynamic publishing features in Movable Type.

Solution

In most cases, enabling dynamic publishing is as simple as configuring the blog's publishing settings to publish dynamically and performing a full rebuild.

Discussion

A SQL database (i.e. MySQL, SQLite or PostgreSQL) is required in order to utilize the Dynamic Publishing feature. Dynamic publishing in Movable Type also requires the web server's support for PHP as well as either custom error documents or mod_rewrite. Most server environments meet these requirements with no extra configuration. If you are administering your own server and want the details on setting it up, please see the section below on Configuring your webserver.

1. Enable dynamic publishing

On the Publishing tab of the blog's settings page, select whether to publish all of your archive templates dynamically or set your templates' publishing modes individually. See Specifying the Publishing Model.

2. Perform a full rebuild

Performing a full rebuild after enabling dynamic publishing will ready the filesystem for dynamic publishing by moving aside any static files previously published by templates which are not set to render content dynamically.

If, for some reason the steps above did not enable dynamic publishing for the pages produced by the templates you specified for dynamic publishing, see the section below on "Troubleshooting dynamic publishing".


How the dynamic publishing engine works

The dynamic publishing engine works by leveraging the web server's ability to respond to the absence of a requested page. In the case of the Apache webserver, this is done either via mod_rewrite or a custom error document directive located in the .htaccess file. In the case of Microsoft Internet Information Services (IIS), it is done using a custom error document for the blog's directory.

In all cases, when web server cannot find the requested file, it is directed (via the .htaccess file or IIS custom error document setting) to serve up content from a the script, mtview.php. This script, known in the default templates as the "Dynamic Site Bootstrapper", handles the request and looks in Movable Type's internal file recordkeeping database for the requested URL.

If a record for the requested page is found, the content of the page is compiled on-the-fly and returned to the client. In addition, it is cached in the templates_c directory to eliminate this step for subsequent requests.

If a record for the page is not found, Movable Type compiles the contents of the Dynamic Pages Error Template (found in the blog's System templates) and returns it to the client to inform them that the file could not be found.

In all cases, if a file exists on the webserver corresponding to the requested URL, the file will be served to the client and the dynamic publishing engine will never be called. This is why a full rebuild is required, during which all static files previously published by the templates you have chosen for dynamic publishing a moved aside by the appending of the string .static to the filename.


Configuring your webserver

If you are an administrator looking to configure your webserver to support Movable Type's dynamic publishing engine, you should make sure that your server is configured as specified in the section below based on your webserver type.

PHP support must be enabled regardless of the web server in use.

  • Apache

You should configure your Apache server to use mod_rewrite if it isn't already enabled. You can use the httpd -l command to list available Apache modules. If the module is dynamically loaded, check your httpd.conf file for a line that begins with LoadModule rewrite_module.

Apache should also be configured to utilize .htaccess files. This also is specified in the httpd.conf file for your Apache installation. An example looks like this:

<Directory />
    AllowOverride All
</Directory>

Depending on your server configuration, this may go in the global context or within a particular VirtualHost section.

  • Microsoft IIS

To support dynamic publishing on an Internet Information Service server, you must configure it to use the mtview.php script to handle errors, allowing Movable Type to intelligently decide when and how to create documents dynamically.

In the Internet Information Services management console, navigate to your Web Sites, and then to the folder where your blog is published. Right-click on this folder and choose "Properties" from the menu to edit its settings.

The last tab of the Properties dialog box will let you edit Custom Errors for this blog. On this tab, you'll see a list of Error Messages for HTTP Errors. Scroll down to the listing for "404", click on it to select it, and then click "Edit Properties..."

The Error Mapping Properties box that pops up will let you select a Message Type for 404 errors. Choose "URL" as your type, and then in the URL box, type in the URL where your published blog is accessible, followed by mtview.php. For example, if you publish your blog to /updates under the C:\Inetpub\wwwroot\ folder, you'll type in /updates/mtview.php.

Click OK to enable these changes to your error mapping settings, and then OK again to commit your changes to the Properties for your publishing folder. You should now be able to enable dynamic publishing for any or all of your templates, and you can test your results by visiting your published blog by clicking "View Site" from within Movable Type.

Do we have more on how you do this?

Troubleshooting dynamic publishing

.htaccess for Apache

When the dynamic publishing option on the blog's Publishing settings page is enabled, Movable Type attempts to create an .htaccess file in the blog's site root directory. If however, one already existed in that location and contained custom content not produced by Movable Type, the application will not alter or replace the existing one. If this describes your situation, see the section below entitled "Dynamic publishing .htaccess file".

mtview.php

On all supported webservers, the dynamic publishing engine requires the presence of the Dynamic Site Bootstrapper, mtview.php in the blog's site root directory. Also, this template must be published statically by Movable Type in order to render other files dynamically.

If, for some reason, you no longer have this template, create a new index template, set the Output File to mtview.php and copy in the following code (always accessible from here) into the template body, save and rebuild:

<?php
    include('<$MTCGIServerPath$>/php/mt.php');
    $mt = new MT(<$MTBlogID$>, '<$MTConfigFile$>');
    $mt->view();
?>

...and make sure that it is not configured to be rendered dynamically.

templates_c directory

On all supported webservers, the dynamic publishing engine requires the presence of the templates_c directory in the blog's site root directory. If the templates_c directory doesn't exist, you can create this yourself. It must have read, write and execute permissions for the webserver (this is usually 777 or -rwxrwxrwx).


Dynamic publishing .htaccess file

If you have a custom .htaccess file in the blog's root directory and hence one cannot be published by Movable Type, the following code can be appended to it to support dynamic publishing for the blog.

Note however that if your blog's site root is located in a subdirectory the domain site (e.g. http://www.example.com/blog), you will need to adjust the all instances of the path to mtview.php in the script below to match the actual location of this file. For instance, if the URL to mtview.php is http://www.example.com/blog/mtview.php, you would use /blog/mtview.php.

# Disable fancy indexes, so mtview.php gets a chance...
Options -Indexes +SymLinksIfOwnerMatch

<IfModule mod_rewrite.c>

# Add mtview.php to the list of DirectoryIndex options,
# listing it last, so it is invoked only if the common
# choices aren&#39;t present...
<IfModule mod_dir.c>
DirectoryIndex index.php index.html index.htm default.htm default.html default.asp /mtview.php
</IfModule>

RewriteEngine on

# don&#39;t serve mtview.php if the request is for a real     
# directory (allows the DirectoryIndex lookup to 
# function)
RewriteCond %{REQUEST_FILENAME} !-d

# don&#39;t serve mtview.php if the request is for a real
# file (allows the actual file to be served)
RewriteCond %{REQUEST_FILENAME} !-f

# anything else is handed to mtview.php for resolution
RewriteRule ^(.*)$ /mtview.php [L,QSA]
</IfModule>

<IfModule !mod_rewrite.c>
# If mod_rewrite is unavailable, we forward any missing 
# page or unresolved directory index requests to mtview.
# If mtview.php can resolve the request, it returns a 200
# result code which prevents any 4xx error code from 
# going to the server&#39;s access logs; however, an error 
# will be reported in the error log file. If this is your 
# only choice, and you want to suppress these messages, 
# adding a &quot;LogLevel crit&quot; directive within your 
# VirtualHost or root configuration for Apache will turn 
# them off.
ErrorDocument 404 /mtview.php
ErrorDocument 403 /mtview.php
</IfModule>

Problem

You want to specify the publishing model on a per-template basis.

Solution

Set the publishing model using the Dynamic Publishing options on the Publishing Settings tab.

Discussion

To begin click the Settings button on the Weblog Toolbar. In the Publishing tab under the "Publishing Preferences" section you will find controls labeled "Dynamic Publishing." If you do not see these options, then you are not using a SQL database; a SQL database (i.e. MySQL, SQLite or PostgreSQL) is required in order to utilize the Dynamic Publishing feature.

The default option, "Build all templates statically," is one in which all content will be generated as static files. "Build only Archive Templates dynamically" is how we recommend that you use dynamic publishing in Movable Type. This option dynamically generates whichever archives have been enabled, such as category, monthly, individual, and so on, and statically generates the index templates.

Selecting the publishing model on a per template basis is a multi-step process that begin with selecting the third option, "Set each template's Build Options separately." Once the option has been selected and your settings saved, an additional control, "Build Options," will appear on the New/Edit Template screen of every index and archive. Go into each template you want dynamically generated, check the "Enable dynamic publishing for this template" box, and save the template.

Problem

You want to selectively rebuild a batch of entries.

Solution

From the Entries Listing screen, check the entries you want to rebuild; then press the Rebuild button.

Discussion

You can now rebuild entries from the Entries Listing screen. Simply check the published entries you want to rebuild and press the Rebuild button. MT will rebuild the pages and return you to the entries listing.

Are dependencies rebuilt?

If the entries you want to rebuild are spread across multiple pages, use the filter to narrow the listing. Suppose you want to rebuild entries assigned to a specific category named "Foo." Use the Filter (See "Filtering the Entries List") to show only entries where the category is "Foo." If the category has too many entries to fit in the listing you may need to adjust your display options to show them all. With those select entries displayed, check all the rows and then click the Rebuild button.

Six Apart
Makers of weblog software and services for individuals, organizations and businesses.
This website is powered by Movable Type.