The personal website of Matt Henderson.
09 December 2005
After three years of using Movable Type, I decided to migrate my weblog over to the open-source WordPress weblogging systems. This article documents the process, and some of the details.
Some of the reasons I decided to make this move included:
mod_rewrite
rules in a .htaccess
file for you.The following sections document the process I followed.
I decided to first setup my weblog on my local MacOS X system, so I could safely configure it and play around, until I felt comfortable enough to move the installation over to our production server.
wp_mattsweblog
, create a new database user wordpress
(and password) in the user
table of the mysql
database, associate the wordpress
user to the wp_mattsweblog
database in the db
table of the “mysql” database. (At this point the DB is ready.)~/Sites
called mattsweblog
, under which I created the standard htdocs
directory (that we use for the web accessible files, DocumentRoot
). Added group writability to the htdocs
directory, so that WordPress will later be able to write a .htaccess
file there.htdocs
directory.Create a new virtual host in /private/etc/httpd/httpd.conf
<virtualhost *:80>
ServerAdmin [email protected]
DocumentRoot /Users/mhenders/Sites/matt.makalumedia.com/htdocs
ServerName mattsweblog
ErrorLog /Users/mhenders/Sites/matt.makalumedia.com/logs/error_log
TransferLog /Users/mhenders/Sites/matt.makalumedia.com/logs/transfer_log
AddType application/x-httpd-php .html
AddType application/x-httpd-php .php
<directory "/">
AllowOverride All
</directory>
</virtualhost>
mattsweblog
pointing to 127.0.0.1. (I did this by duplicating another entry.) This lets me access my local site via the URL via http://mattsweblog/
Accessing the URL http://mattsweblog/
, I was shown a welcome screen that pointed me to the WordPress installation link. I clicked on that link, and within about 30 seconds, my WordPress installation was up an running. WordPress created the administration user, and gave me the password.
I made the following customizations and modifications to my WordPress installation (in no particular order).
mattsweblog
), and edited its name in the style.css
file, in order to distinguish it from the default, in the Themes area of the administrative interface. I then activated the mattsweblog
theme, within the admin area.template-functions-post.php
file to create a static link under the dynamically built “Pages” section, to create a link to the “home page” (since clicking in the page header might not be obvious to all users.)Markdown
plugin in the Plugins area of the admin interface. (The Markdown plugin lets you write your articles using the Markdown syntax, which is simpler and easier for humans to read, than HTML marked-up text.)My own comments. I wanted the background color of my own comments to be different, so I added the following to the comments.php
file:
< ?php if((get_comment_author() == "Matt Henderson") or
(get_comment_author() == "mhenders")) {
$oddcomment = "self";
} ?>
I then edited the style.css
file, duplicating the .alt
class, and changing the background color to something yellowish.
Options -> Permalinks
admin area, I changed the permalinks structure to one of the proposed defaults (http://weblog/2005/01/05/article-name
).content/
which sits at the root of the htdocs
directory. In here, I put images, php libraries, you name it.At this point, I was ready to import my Movable Type data into my WordPress installation. I followed the MT migration procedure pretty much to the letter, and ended up with a import.txt
file on my local system, containing my MT data.
I opened the file in BBEdit, and Process Lines Containing...
to locate all the places on http://matt.makalumedia.com
where I’d referenced images, files, etc. I then moved all those resources from the server to my local setup into my content/
directory, using Transmit, my SFTP client. (Fortunately, there were no name clashes.)
Once that was done, I used BBEdit’s grep function to change all absolute resource references in my MT data file to relatively reference the resources in content/
.
Next, I used BBEdit’s grep feature to remove all Ping
blocks, since probably 99.9% of those were spam. (I think I could have done this easier via SQL query to the DB.)
As per the MT migration procedure, I then imported the MT data file into WordPress. It worked without a hitch.
Finally, I issued this SQL statement to the database, using CocoaSQL in order to empty all the excerpts (since I’ve always been in the habit of copying the full article body into the excerpt):
`update wp_posts set post_excerpt = "";`
The next thing to tackle was the handling of old URLs. In MT, my old URLs looked like:
http://matt.makaumedia.com/archives/000833.html
Since a couple of people out there (and Google) have linked to some of my articles, I want to make sure they continue working. And, perhaps most importantly, I want to make sure all those RSS feeds still continue to work.
The Apache web server has a module called mod_redirect
that can handle redirecting one URL to another. The module gets its information from either httpd.conf
file or a websites local .htaccess
file. Fortunately, mod_rewrite
is enabled by default in Mac OS X systems.
So, I added the following to the local .htaccess
file which WordPress created when I updated the Permalinks settings:
ErrorDocument 404 /index.php?error=404
RewriteRule index.rdf /index.php?feed=rdf
RewriteRule index.rss /index.php?feed=rss
RewriteRule index.xml /index.php?feed=rss2
RewriteRule archives/000833.html /index.php?p=160
RewriteRule archives/001556.html /index.php?p=177
That’s not an exhaustive list, but you get the idea.
404.php
file found in the Theme.And, as per described by the wonderful support community, the “additions” should be kept outside the WordPress managed block within the .htaccess
file, indicated by # BEGIN WordPress
.
Instead of setting up redirects to all my articles, I’ve decided to add the following to my 404.php
WP script:
< ?php
$exceptions = array('favicon','robots.txt');
$sendEmail = true;
foreach($exceptions as $exception) {
if(eregi($exception,$_SERVER["REQUEST_URI"])) {
$sendEmail = false;
}
}
if($sendEmail == true) {
$to = '[email protected]';
$from = '[email protected]';
$subject = 'Weblog 404: '.$_SERVER["REQUEST_URI"];
$message = "";
foreach( $_SERVER as $key => $value) {
$message .= $key." : ".$value."n";
}
mail($to,$subject,$message,"From: $from");
}
?>
This PHP code sends me an email with the details regarding failed requested URLs (and lets me maintain a list of exclusions, like favicon
). I’ll monitor these emails for a while, adding frequently requested files to the .htaccess
file (and then remove this code when I’m comfortable that things are stable.)
After creating some content Pages
(like “About”, “Contact”, etc.), I was satisfied with the local setup, and ready to move everything over to the operational (Linux) server.
matt2.makalumedia.com
. My strategy was to setup the site under matt2
, and then switch over matt
once I was happy.htdocs
directory to the equivalent directory on the server..sql
file. My sysadmin was worried about feeding a UTF-8 encoded file to our production MySQL server, so before moving the .sql
file to the server, I re-encoded it to Western Latin-1 using BBEdit. (I don’t write using extended characters that often, so I knew this wouldn’t be a big deal.).sql
file for http://mattsweblog
to http://matt.makalumedia.com
, so that the site would work once the data was imported on the server. (Well, actually I didn’t do this, and later regretted it.).sql
file to the server, and the system administrator imported it to the MySQL database. At this point, the site was pretty much running properly.matt2.makalumedia.com
was working, the system administrator added matt.makalumedia.com
as a ServerAlias
to the matt2
virtual host, and restarted Apache.At this point, the new weblog was up and running on the server with WordPress.
Hope this article helps anyone out there looking to do the same. Don’t hesitate to ask if you have any questions.
Enjoy this article? — You can find similar content via the category and tag links below.
Questions or comments? — Feel free to email me using the contact form below, or reach out on Twitter.