Archive for the ‘Programming’ Category

Movable Type Installation on Windows Server 2003

Wow, what a pain in the ass. I’m glad I didn’t personally pay for this software. I thought this was yet another PHP content management system.

Nope, it’s Perl.

To hopefully save someone from searching all over the web and back, here are the problems I encountered while installing. This guide assumes a semi-proficient knowledge of IIS configuration.

Install ActivePerl

First off, make sure you install ActiveState’s ActivePerl on your server. Manually configuring Perl is not something I’d care to dive into. If that’s your bag, go to CPAN (and why the hell are you reading this guide?).

Using the IIS Manager, navigate to your website and choose “Properties”. Under the “Home Directory” tab, click the “Configuration” button.

In the Application Configuration window, click the “Add” button.

Use the following values in the Extension Mapping dialog:

Executable: C:\Perl\bin\perl.exe "%s" %s
Extension: .cgi
Verbs: Check “Limit to:” and enter GET,HEAD,POST
Uncheck the box labeled “Verify that file exists” (this will speed execution on scripts)

Next, select the “Web Service Extensions” item on the left of the IIS Manager (at the same level as “Web Sites”). Select “Perl CGI Extension” and click the “Allow” button.

I already had PHP installed on this server, so I’m skipping that step for this guide. PHP is far less tricky to install, anyway, and there are extensive guides for this already.

Fix Shoddy Installation Procedures

When navigating to my Movable Type directory, I immediately encountered the error “CGI Error The specified CGI application misbehaved by not returning a complete set of HTTP headers.”

Bad CGI application, bad! Smack it on the nose with a rolled up magazine!

First off, you should run the mt-check.cgi script to make sure everything’s on the up-and-up. If the script runs successfully, you’ve successfully installed and configured ActivePerl. Yay, you’re halfway (yes, halfway) there!

Near the top of this page, you should see the following:

Current working directory: [path]
MT home directory: [different path]

The MT Knowledge Base says to download this modified Bootstrap.pm file, and replace it with the version on your server. I honestly don’t know what’s different about it, or why they couldn’t include it with the installation, or even if it does anything different. Mindlessly obey.

The same page also advises to “Create a new “virtual directory” under IIS which points to the physical directory where the Movable Type CGI files are located (i.e., the “MT home directory” mt-check.cgi reports)” That explanation is freaking stupid. What it should tell you is “Do not install MovableType directly into the folder you wish to present to the world.” As in, I moved the entire thing to /cgi-bin/ and created a virtual folder named “blog” under the root folder pointing to /cgi-bin/. Your CGIPath variable in mt-config.cgi should match your virtual folder name (like http://www.example.com/blog/).

Install MySQL Driver

Oops, now navigating to the blog URL results in an error saying that the MySQL driver is missing (sharp readers will notice this was missing in mt-check.cgi as well, I did not). On your server, run the ActiveState Perl Package Manager, which should be in your Start menu. If you scan through all packages, you’ll notice a DBD-mysqlPP module. This will not work, as far as I know. You need to add another repository source to get the actual module you need.

In PPM, go to Edit > Preferences, then go to the “Repositories” tab in the preferences window. Add the CPAN repositories to its sources by either selecting “uwinnipeg” from the “Suggested” list, or do what I did manually. Enter “CPAN” for name, and http://cpan.uwinnipeg.ca/PPMPackages/10xx/ to the location box, then click the “Add” button. You should now have DBD-mysql available for installation. Install it.

That should be it! As far as configuring MovableType goes, that’s where I get off, because this installation was for a client who already knew how to use it, and already had his login information in the database (this was a server move).

Good luck!

ASP.Net MVC

If you’re using IIS and ASP.Net…I fart in your general direction. I discussed this URL-rewriting feature (Using a single file to handle all requests) on one of our portals with our lead .Net developer, and his response was a gruff, “well, if Apache can do it, I can do it…” A week later, I am asked which config file I want to store my URL entries in.

Sigh…

The whole point of URL rewriting is so that you don’t have to do stupid crap like “update another file that contains information about the file you just added/deleted.” Then a few days later he tells me that it can happen, but the URLs must be in the format /info/page-name.aspx. Not that I mind too much, as it’s basically what I asked for, but it doesn’t seem that hard. I mean, I’m not an expert ASP.Net developer. I don’t even like
ASP.Net. This is now another reason added to the many reasons I don’t like it.

A few days ago, I heard about ASP.Net MVC (via Scott Gu’s blog, no link love for Microsoft, because their description doesn’t say anything meaningful).

It includes a very powerful URL mapping component that enables you to build applications with clean URLs.

Clean URLs. Like the one at the top of this page. Like the ones you see on CodeIgniter, WordPress, ExpressionEngine, and most other PHP/Apache sites out there. My guess is I’ll get one more week, maybe two before we’re rewriting with ASP.Net MVC.

.htaccess Snippets

Here are some .htaccess snippets I’ve had to use, and hopefully someone will find them useful.

Moved from one URL to another: My old blog url used to be verbose.pixelbath.com, and before that was pixelbath.com/verbose. Setting aside the notion that I move my blog around too much, the following snippet…

RewriteEngine on
RewriteCond %{HTTP_HOST} ^verbose [NC]
RewriteRule ^(.*)$ http://www.pixelbath.com/blog/ [R=301,L]

…which means any hostname with ‘verbose’ will be redirected to the main blog URL. Useful because many sites had me linked to the old blog, and I didn’t want to break their links too badly. Nothing fancy, so please note that this does not transfer url parameters. It only redirects requests with the single word ‘verbose’ to the main blog URL.

Using a single file to handle all URL requests: If you’ve used almost any PHP CMS or MVC framework such as CodeIgniter or CakePHP, you’ve probably used something like this for “search friendly URLs”:

RewriteEngine On
RewriteBase /blog/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (.+) /blog/index.php [L]

What this does is start from the /blog/ folder, and handle any requests under that. The first RewriteCond sets our rule to not apply to any physical files matching the request, and the second does the same for physical directories.

Once it passes the two conditions (a request in /blog/ that is not a physical file or directory), it goes to the RewriteRule, which simply takes all matching requests and redirect them internally to /blog/index.php. This is not a browser redirect, so the user will still see the URL the way they found it, something like http://example.com/blog/archive/foo. I use this technique on the comics pages by parsing the URL segments into comic and page requests.

Stop image and/or content hotlinking: Some netizens are either not savvy with the way the Internet works, or don’t give a crap because idiocy prefers the low-hanging fruit. Either way, I’ve actually got a few snippets for this purpose.

RewriteEngine On
RewriteCond %{HTTP_REFERER} !^http://(.+\.)?myspace.com [NC,OR]
RewriteCond %{HTTP_REFERER} !^http://(.+\.)?blogspot.com [NC]
RewriteRule ^.*$ http://www.yourdomain.com/ [R,L]

The preceding snippet will block specific websites and their subdomains from hotlinking from your site, but will allow any other site not specified in your .htaccess file to do so. If you’d prefer to stick another image in place of the hotlinked one, this is particularly adviseable when you, (often with amusing results):

RewriteEngine On
RewriteCond %{HTTP_REFERER} !^http://(.+\.)?yourdomain\.com/ [NC]
RewriteCond %{HTTP_REFERER} !^$
RewriteRule .*\.(jpe?g|gif|bmp|png)$ /images/goatse.jpg [L]

This one will take any request with a referer not originating from your domain, or blank referers (because some users do legitimately blank their referer string), and redirect them to an image elsewhere on your site. This will work “inline” and display whichever image you specify on outside sites.

If you’d prefer to be plain and simple though, you can just set HTTP code 403 (Forbidden) on any image for any of the rewrites in this section. Simply replace the RewriteRule of each with:

RewriteRule .*\.(jpe?g|gif|bmp|png)$ - [F]

Which simply sets any request for any image to 403 (Forbidden). Obviously, it should be used in conjunction with RewriteConds.

Dammit, Microsoft…

Why, when I’m over being pissed off for something, you go and pull additional bullshit?

Installed .Net Framework 3.5 SP1, and after restarting Firefox for unrelated reasons, notice that a new add-on has been installed:

Like a virus

Like a virus

The installer didn’t ask, and what’s this? I can’t uninstall it? Are you fucking kidding me? Oh look, they changed my user-agent string too:

Go away!

Go away!

To remove this bullshit, do the following:

  1. Open Regedit
  2. Goto HKLM\SOFTWARE\Mozilla\Firefox\extensions
  3. Delete the key {20a82645-c095-46ed-80e3-08825760534b}
  4. Restart Firefox.

To remove the user-agent string (add-ons like User Agent Switcher will not change the default), open the about:config page, and in the Filter box, type “useragent” and you should see “general.useragent.extra.microsoftdotnet” somewhere near the top.

Reset this value so it becomes empty (it will be automatically deleted).

Fuck you, Microsoft. Next time, ask. You also went out of your way to ensure it couldn’t be uninstalled. What’s up with that? Just provide a link to the installer. If the add-on is something we want as users, we can install it ourselves.

Update (9/19): Commenter Matti brings up that it’s because of the method of install that you can’t uninstall this add-on, like any other add-on installed via the registry.