You might have noticed that, now, if you scroll to the bottom of the blog or any of the categories, the site is now paginated, making it easier to browse the categories and archives. You have no idea how much of a pain it was to implement this--it required me to set up dynamic publishing, which is a special case on NearlyFreeSpeech.NET, the company that supplies my web hosting. They have a lot of security restrictions in place on their default PHP configuration (PHP Fast Mode).
There are no up-to-date guides out there on how to make this work, so I spent the better part of yesterday toying with my files and reading old documentation, trying to tease out what was still accurate and what wasn't. Here's what I found.
The easiest way to make this work is to use PHP Flex Mode instead of Fast Mode. Change your site's server type to "Apache 1.3, PHP 5 Flex, CGI" on your site's information page on the NFS Member Dashboard. Flex Mode automatically runs with the same paths as your CGI scripts, so no code manipulation is required.
Flex Mode is also supposedly slower, but I didn't actually see a significant performance hit in comparison to Fast Mode. If your whole site is being published dynamically or is huge, though, using Flex Mode may not be feasible. If that's the case, you better have a working understanding of UNIX/Linux file paths and at least some familiarity with Perl and PHP, because you're going to be making some small code changes.
Digging Into the Code
With the help of this blog post, I found the lines of code you need to change. MT's codebase has changed since that post was written, so it took a little searching. Everything I say here applies to MTOS 5.04. Any other version may be different, though recent ones are probably not significantly.
All file paths I discuss are in relation to your MT application directory, which is probably something like /home/public/cgi-bin/mt.
First we look in file lib/App/CMS/Blog.pm. This is the Perl file that contains the subroutine (_create_mtview) that builds mtview.php, the file that Movable Type uses to generate your dynamically-rendered webpages.
The lines you need to add are in boldface. Replace "/f2/mysitename" with your site's Apache Site Root (you can find this in the Member Dashboard, on your site's information page):
sub _create_mtview { my ( $blog, $site_path, $cache, $conditional ) = @_; my $mtview_path = File::Spec->catfile( $site_path, "mtview.php" ); eval { my $mv_contents = ''; if ( -f $mtview_path ) { open( my $mv, "<$mtview_path" ); while ( my $line = <$mv> ) { $mv_contents .= $line if ( $line !~ m!^//|<\?(?:php)?|\?>! ); } close $mv; } my $cgi_path = MT->instance->server_path() || ""; $cgi_path =~ s!/*$!!; my $mtphp_path = File::Spec->canonpath("$cgi_path/php/mt.php");# NFS.net path hack for perl/php compatibility in dynamic publishing $mtphp_path =~ s|^/home|/f2/mysitename|;my $blog_id = $blog->id; my $config = MT->instance->{cfg_file};# NFS.net path hack for perl/php compatibility in dynamic publishing $config =~ s|^/home|/f2/mysitename|;
After you make this changes, delete your old mtview.php files (if any) and re-publish your dynamically published pages. New mtview.php files will be generated with the correct paths.
Next, we need to look at php/mt.php. This is a PHP script whose functions are used by mtview.php.
You only need to change one line:
function configure_paths($blog_site_path) { if (preg_match('/^\./', $blog_site_path)) { // relative address, so tack on the MT dir in front $blog_site_path = $this->config('MTDir') . DIRECTORY_SEPARATOR . $blog_site_path; }// NFS.net path hack for perl/php compatibility in dynamic publishing $blog_site_path = str_replace("/home/","/f2/mysitename/",$blog_site_path);
No need to republish after this change, since this PHP script is accessed on the fly. Make sure mt.php has proper permissions--otherwise you will see some very obtuse messages, such as the ever helpful "An error occurs."
After all this, you should be able to dynamically publish on PHP Fast Mode servers. Without these changes, you will probably just see a lot of "open_basedir" errors when you visit a dynamically-published page.
Of course, all of this is only meaningful for my fellow NearlyFreeSpeech members. If you have another host, this information will probably not be helpful.
After you get dynamic publishing working, you can set up pagination according to Movable Type's documentation:
- Pagination for Dynamic Publishing - I didn't do the .htaccess change, only the template changes. I used this for my archives only (the Entry Listing template).
- Paginating the Main Index Template - This was how I did the pagination for the main blog index. You can publish your main index statically with this solution, and static publishing is faster for the end user.
Leave a comment