April 27, 2004


When you are first setting up a new weblog, Movable Type prompts you to choose a file extension in the weblog config preferences section. The default setting is HTML.


If your server allows PHP scripts, and you would like to add customization features that aren't part of the default Movable Type system, it is highly recommended that you choose PHP as your default file extension preference in place of HTML. Doing so allows you to take advantage of many freely available PHP scripts to help customize your weblog. PHP is an open source scripting language that is powerful, stable, and extremely popular for adding dynamic elements to websites. In your Movable Type weblog, PHP scripts can allow you to do random photos, includes, and skinning, among many other things. PHP can also help you create a more modular approach to building your templates, thus reducing rebuild times.

To give your entire weblog php extensions, write php in place of html where prompted in the weblog config preferences section. In the weblog config archiving section change the archive file template extensions from html to php. On your index templates, change the extensions of your output files to php. (See the Converting to PHP Tutorial to convert your site to PHP.) If you only want to invoke a PHP script on the Main Index and not on any other pages (for example to generate a random photo on your main page), just change the output file of the template from index.html to index.php. (If you do this, make sure to delete the index.html file from your server (using an FTP program). Left of the server, the index.html file will served instead of the index.php file.)

Cool things to do with PHP:
PHP Skinning Tutorial - Domesticat.net
Random Image Rotation - PHP script from A List Apart
Relative Dates PHP script - change from "Posted Aug 1" to "Posted 3 days ago".

Scripty Goddess
Converting to PHP - LMT Tutorial
MT Forums discussion on some PHP installation problems
An Introduction to PHP by John Coggeshall

Has this tutorial been helpful? Please consider linking to Learning Movable Type at http://learningmovabletype.com/ . Thanks!

Posted by Elise Bauer on April 27, 2004 to Beginner Tips, Install, PHP
Comments(8) | Email to a friend | Printer-friendly version


If you would like to send a trackback
please use the following URL: http://learningmovabletype.com/cgi-bin/mt32/mt-tb.cgi/221


Good article! However... :)

It is true that using PHP allows great flexibility in building dynamic scripts. However, for people (or blogs) that do not really need this, HTML is *much* preferable, since it generates static pages. The points?

1. Caching. Since the pages never change (unless you rebuild them, of course), your browser, your HTTP proxy *and* your webserver can all cache them instead of transferring them, thus saving time and network traffic.

2. Server load. If your webserver is asked to serve a file with a 'php' or 'php3' extension, it passes the file to its PHP interpreter. Even if the interpreter is a build as a module, this still adds some overhead to the processing - and if you have no PHP code within the page, this is absolutely unneeded overhead that can slow down your server a lot.

So basically.. the recommendation to use 'php' as the file extension should only be given for blogs that *will really use it* - for the rest, it *will* result in more network traffic and more server processing.

Peter - thanks for the clarification! I've been searching the MT forums for the "downside" and hadn't found any. I've been using php on several of my blogs now for many months without a problem. In fact, it greatly speeds up the rebuilding process. But if you weren't planning to do any customization that might require PHP then it's unneccessary.

I don't use PHP on my site, but instead use several JavaScript includes combined with various Template Modules. The Template Modules are very useful, just like an include, but it's all contained within MT (that means, however, that you can't edit them outside of MT). I actually have my main page include 3 modules: the information between the HTML head tags, the sidebar content, and the main blog content. The head module even includes yet another module that includes all of the stylesheet information, and the sidebar includes various javascript files for my sub-blogs.

I just started using MT today... But another easy way to add php to your site would to be to use a .htaccess file to force apache to parse whatever page(s) as php, or just set it to parse all html pages as php. Its pretty easy, here is a sample

Create a new file and save it as .htaccess making sure that you save it as type "all files" and not as a text file or it won't work.

In that file if you want apache to parse all html files as php scripts, put this line in and save the file, just upload it to the directory where the html files you want to treat as php are:

AddHandler application/x-httpd-php .html .php

Or, you can just force one page to be parsed as html putting this line in the file instead:

Forcetype application/x-httpd-php

Hope this helps more then confuse. Just do a google search for .htaccess files and apache and you get more then enough info.

Hi Kenrick,
I think you lost me at the word "parse"! I may cover .htaccess in a separate tutorial some time, but not until I figure it out well enough to not do damage. Given that I really don't know what I'm doing I could potentially screw something up. When I have played with the .htaccess file on my site I've had to have my webhost's tech support guy talk me through it. In the meantime, MT's built-in file extension preference works perfectly well for creating php files. :-)

To follow up on an earlier comment left by Peter, I was under the impression that the php static pages that MT produces are cached by the browser, just like HTML. Someone please correct me if I'm wrong.

So if we blew it and set up with html as the default can we change to php easily? Should we?

Hi Barrett,
You only need to switch to php if you want to take advantage of some of the dynamic capabilities that php offers. You can very easily change to php.

Comments are now closed for this entry.

Email to a friend

Email this article to:

Your email address:

Message (optional):