21 April 2008

Movable Type 4 Setup on Ubuntu

I am in the process of consolidating my blogs to a single system, and in doing so, am switching to Movable Type. This blog will eventually move, but the initial impetus was for some other blogs that were running on WordPress where I was having some problems (and spent way too much time trying to fix that - one of the key things I don't want to be doing with my blog system). But, in relation, I found the setup instructions for Movable Type a bit lacking, especially in relation to using multiple blogs, and how this works in terms of Apache and MT setup.

I also want to say a bit thanks to Duncan for showing me his Apache config, and some brief discussion of multiple blogs with MT. The MT docs were really lacking here as said, but Duncan's knowledge made it clear this was pretty easy and a nice way to go. Thanks Duncan, and check out his blog and site, and of course all his great pics on Flickr.

I am using a single installation of Movable Type, supporting multiple blogs, with each blog having their own domain name, and that blog (or really the MT content) living at the root of that domain name (this last part isn't required/essentially for this tutorial, you can easily tweak the Apache config).

So, with that, given that it actually turns out to be relatively simple to set up once you know a few key bits, I figured I'd pass along what I did...

First, I created my standard Ubuntu slice at Slicehost. I host everything with them these days, and as such, I have a base system image that I've built for myself. It's built with their standard Ubuntu 7.10 choice, and then I make tweaks to the SSH setup, add a few bits I need, etc. But, I believe you could simply take pretty much a standard Ubuntu server install and use that. Please let me know if this guide doesn't work for you in that case.

Preparations



In preparation for the move, while my existing blogs were running, I exported their data from WordPress using WordPress' Export feature, which produces a WXR file. Save that to my local machine.

I also made sure I had my domain names secured, and the DNS for them setup. In particular, one thing to note is that Movable Type is sort of a two part system. You have the MT web application, which is a publishing application, but is not what someone hits when visiting your blog(s). MT publishes your blog out as static content (or that's the default option anyway). So, I setup an "mt" subdomain on one of my domains where I will access MT (more on that below).

Apache and Perl Install



Apache 2 and mod_perl were not on my system by default, so I needed to install those. This amounts to:
sudo apt-get install apache2 libapache2-mod-perl2 libapache2-mod-perl2-doc

The above will not only install it, but configure mod_perl for use in Apache, and you can now run Perl based web apps (MT is developed in Perl). Also, depending on how you want to do email, you may need to install Perl's Mail::Sendmail (if using SMTP; if you use sendmail, then you can choose that when setting up MT):

sudo perl -MCPAN -e "install Mail::Sendmail"



Create a Database



I created a database for MT using MySQL. I also setup a specific MySQL user, password, and assigned them rights to that database. You'll need this info later when setting up/configuring MT.

I have been using Navicat for nearly all my DB management. It works really well given it can do SSH tunneling as I don't open the MySQL port on my servers, etc. It is a commercial app, but as a developer who works with DB's often, has proven to be my tool of choice (I've tried many others, and this is the one that's worked best for me).

Apache Configuration



I have a relatively minimal Apache configuration file. The bulk of it is done with a file that sets up my virtual hosts (several domains point to a single machine). The setup for MT has a few critical pieces:

  • Setting a ScriptAlias for the "mt" directory, so mod_perl knows to execute .cgi files there.

  • Setting an Alias for the "mt-static" directory, which is MT's static content, and which you'll want to be referenced from all your blogs. You can also do this with a symlink, but I've done it with an Apache alias below so that I don't have to worry about a given blog's static content getting wiped out and breaking this (if the static content gets wiped out, you can just republish in MT to restore it, so I prefer to keep that purely maintained by MT).

  • Setup the proper options/settings for the MT directory.



Thus, my configuration for my virtual hosts looks like the following (fake domain names used), notes following:


NameVirtualHost *
<VirtualHost *>
ServerAdmin chris@example.com
ServerName mt.example.net
DocumentRoot /var/www/mt

Alias /mt-static /var/www/mt/mt-static
<Directory /var/www/mt/mt-static>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>

ScriptAlias / /var/www/mt/
<Directory /var/www/mt>
AllowOverride None
Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
Order allow,deny
Allow from all
</Directory>
</VirtualHost>

<VirtualHost *>
ServerAdmin chris@example.com
ServerName example.com
ServerAlias example.com www. example.com
DocumentRoot /var/www/example

Alias /mt-static /var/www/mt/mt-static
<Directory /var/www/mt/mt-static>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
Redirect /mt.cgi http://mt.example.net/mt.cgi
</VirtualHost>


The first VirtualHost block sets up where I'll access MT, thus at http://mt.example.com. There you will see both the Alias for mt-static, and also the ScriptAlias for mt. These are critical.

The second Virtual Host block defines one of the actual blogs, which will be accessible at http://example.com or http://www.example.com. For additional blogs, you would add another of these blocks per domain name. The key bits here are the DocumentRoot and the Alias for mt-static. The DocumentRoot is where you will have MT publish your static blog content. Make sure that directory is writable by Apache/MT.

Finally, the Redirect sets things up so that when you are logged in and visit your blog, and see the various links for "Edit this content" that those will actually work (they point to mt.cgi, so this redirects them to whatever domain is serving mt).

Setup Movable Type



Next, visit http://mt.example.com/mt.cgi in your browser to begin setting up and configurating Movable Type. It will ask you about your database, and a few other bits, and then prompt you to create the first blog. Make sure the blog URL and directory match what you setup in your Apache configuration above. Beyond this you will need to refer to Movable Type docs for questions. But, you should essentially have a blog running, and will just need to Publish it to have MT write the static files into the directory you've defined.

The last step for me was to import my blog content from my prior WordPress setup, using the WXR dump I created at the beginning of all this. One key note here. When you go into MT's Import page - choose the blog you want to import to (even if you only have one) first. Only then when you pick WXR (if appropriate) for your import will it give you the proper fields for the info it needs for the WXR import. Otherwise it'll set your import type back to MovableType, and claim it has read in your import file fine (but you'll of course have no content).

I'm still tweaking my templates and doing a few bits to the sites I'm moving over, so I'm off to continue on that. Hope this helps someone.

15 comments:

Anonymous said...

Great step by step tutorial - helped me a lot.

Anonymous said...

Chris, I am still learning about MT so bear with me. I am wanting to do the exact same thing - run different blogs with different domains but on the same server with one MT4.1 install. I get the need for a virtual host, but where exactly, or what file do I need to put this code into? Thanks!

Lydia said...

Hello from Silverton, Oregon, and congrats on being recognized as a Blog of Note!

I'm teaching myself HTML, which shows you how far behind your blog content I am! But my husband will LOVE this stuff so I'll bookmark your blog for him.

Chris said...

@Tina, The virtual host configuration goes into your Apache configuration file (likely a file in /etc/apache2, either apache2.conf or maybe httpd.conf). I should have noted that I'm assuming a system where you have root access, and can change a core configuration file like that. If you are on shared hosting this won't work. These instructions assume (again, I should have stated this) that you have some system administration type experience on Linux or similar, and root access, and all that.

Anonymous said...

thanks for your resonse Chirs. yeah, I'm on a shared server, so that would be why I can't find a file to configure... Do you perhaps know of another work around for this without using the virtual host? I tried copying the mt-static file to the other domain, but I'm just getting text for my new blog as none of the formatting shows up. I'm guessing it's not accessing the .js files correctly. Any suggestions are greatly apprciated.

Chris said...

@Tina You may be able to do something with .htaccess, but not sure. I would recommend a couple alternatives honestly... Either get a VPS account, as shared hosting typically sucks, and/or get something somewhat in between, like I think Media Temple does 1-click installer for Movable Type (how they handle multiple domains into a single MT install I'm not sure, but I imagine they can help you with that). Also, for whichever shared hosting you're on, you could check their forums and see if anyone has done this, etc.

Anonymous said...

I tried accessing .htaccess already and it's read only - I guess that's the shared server thing. I was running MT3.4 and upgraded to 4.1 and that was fine. But now I'm wanting to add that other blog for another domain and clearly I'm seeing the setbacks of being a shared server. I'll reach out to Media Temple and see if they can assist. thanks for your help. Tina

Chris said...

Tina, there are a couple keys to getting this going:

1) Tell MT where to publish the second blog - you'll have to pick a spot on the disk that you can have it write the files to.
2) Be able to tell your web server (Apache) where the DocumentRoot is for the domain name (which would be the directory from #1).
3) Tell the web server where the mt-static directory is. This is shared across your install of MT, but each virtual host/domain will need to know where to go find it. An alternative however would likely be to just create a symbolic link to it in your directory from #1 above. That way, in your shared host settings, all you really have to do is point your DocumentRoot to the right place. So, depending on how your shared host is set up, that may simply be telling MT to publish its files for that domain to the directory your shared host sets up for the web files for that domain.

Derek said...

Not a big fan of Ubuntu, but great blog.

Anonymous said...

whats unbuntu?

Anonymous said...

Why did you install mod_perl? That's not needed as MT is run via CGI.

Chris said...

Rob, good point (on mod_perl). I believe I had done that when I was having trouble getting Apache to execute Perl, but you are most likely right in that it is not needed, and I likely just had something else misconfigured at some point.

Viorel Stirbu said...

It's not enough to redirect just mt.cgi because comments and search will fail. You need to redirect several (or all) cgi scripts, so here's my redirect :

RedirectMatch ^/(mt[a-z-]*.cgi.*) http://example.com/$1

Enjoy ;)

Unknown said...

Chris,

Been trying this weekend to bring MT up on Ubuntu, and your tutorial helped a lot.
However, i am having an issue with it, more specifically, with the font end.
The backend admin works great. However, it's when i try to access the front end, i get the page, but all the remaining files such as javascript or css are not loaded.
The errors in apaches error log are: Permission denied: exec of '/var/www/mt/example/styles.css' failed
Premature end of script headers: styles.css
Any ideas?

Chris said...

Ognen, that's a pretty strange error, since it shouldn't be trying to execute a CSS file. I'd try to figure out why it's trying to execute a CSS file.