Skip to: Navigation | Content | Sidebar | Footer


Weblog Entry

ASP to PHP, with MT to Boot!

December 02, 2003

Step right up, step this way. Ladies and gentlemen, I give to you the amazing journey from one server-side technology to another. You’ll be amazed, you’ll be awed, you’ll laugh, you’ll cry. You’ll… okay, so my writing style needs to calm down a touch.

I’ve been working on this on and off for months now, and I meant to have it up far earlier than this. Some of the final details are fuzzy at this point, but the bulk of it is on target.

This is the process I went through when upgrading my Movable-Type powered site from IIS (and ASP) to Apache (and PHP), from start to finish. For the benefit of Google, and you the reader, I’ll try to spare no detail. Much the same as I ended up blessing the kind souls who have written up their own experiences, one day I hope someone will find the exact answer they need somewhere in this.

Why I Switched

I originally set up mezzoblue on an IIS host because ASP is what I knew. I am not a programmer, but the odd time I needed to fool around with code it had to be something that I could easily use.

When I created BlueSpark (a free, light-weight ASP-based content management system: think server-side Notepad) I realized even my knowledge of that was only rudimentary at best. So reasons to stay on IIS quickly eroded, and I found myself wanting to get into PHP about two or three months ago. Why PHP over ASP? Momentum, baby. All the cool toys are written in PHP, and more importantly, a large chunk of them are open.

I’m no anti-Microsoft zealot, but I see huge advantages to working with open source software. Now that I’m actually on an Apache server I can say that custom .htaccess files are a hugely important thing to have, and IIS’s handling of the same is positively archaic in comparison. I’m sure there will be plenty of other little gems I’ll discover as I play more.

How I Learned

So cut to about a month ago. In my copious, vast amounts of spare time I started thumbing through a Peachpit press book by Larry Ullman: “PHP and MySQL For Dynamic Web Sites.” If you’re familiar with C/C++/Javascript syntax, you’ll easily breeze through the first 50 or 60 pages. In fact, I skipped to Appendix A which covers installation, and with a little help from the manuals I managed to get Apache, PHP, and MySQL up and running on my spare Windows laptop one evening.

By the time I was a hundred pages into the book, I’d already started working on converting mezzoblue. There aren’t many scripts, and a lot of the work involved rebuilding my main three server-side includes. I hadn’t really dealt much with the content pages within, I had only laid the foundation.

What to Do When Things Go South, or: Motivation

And it was about this point my IIS server began acting up. Reliability decreased over a good week, and then one day things just stopped working about 80% of the time. It was down, then up, then down again. My host’s site suffered the same problems, so I couldn’t even file a claim to see what was going on. Needless to say, when I finally got an answer it was less than satisfactory.

So I started investigating hosts. I need generous bandwidth and storage space, but I don’t use a lot of server processor time. Unfortunately, the amount of bandwidth I use gets lumped into higher-end accounts. But Matt Mullenweg made me an offer I literally couldn’t refuse, so I jumped.

Static Conversion

But that’s only the beginning, of course. I had a host. Now to port Movable Type, and rebuild my site on Apache. Well, let’s just say this wasn’t as easy as I had hoped it would be, but it didn’t turn into the disaster I had feared it might.

I had backed up all my files from my IIS server earlier in the week, and I was irritable enough with the downtime that I decided to jump in head first and initiate the domain transfer. I put up my pre-built PHP page with an apology message for the next day or two of downtime, and went to work. I started with the static content, that was easy enough. I plugged in my new iBook and grabbed a copy of BBEdit Lite, and started re-linking.

The nice thing about server-side includes, of course, is that all your standard site-wide bits like headers and footers and sidebars and the like can be stored externally in their own individual files. The upshot in this case is that a lot of my static content looked like so:

inlude files, content, include files

Not a lick of content had to be changed, all I had to do was re-link the new include files, which, if you’ve been paying attention, I had already built last month. Copy, paste, upload, test. Copy, paste, upload, test. That was a fun evening, at least in comparison to what happened next.

Movable Type, or, How to Make a Bad Thing Worse

Now here’s where I hit the big snag. Equal parts assumption and hope had led me to try uploading the entire Movable Type install to my new server. After all, MT is Perl-based and should work without a hitch. I made sure server-detection in my FTP program was automatic (since it’s very important you’re not uploading .cgi files as binaries), dropped the works onto the server, re-linked Perl and the appropriate user directories, set my permissions, and loaded the MT interface.

Nothing.

Well, not nothing, but not a lot more: Error 500, internal server error. Not helpful. I double-checked my paths and my permissions, then tried again. Still nothing. In a fit of desparation I dropped one of the .db files into a text editor and noticed that there were paths in those consistent with my old IIS install — not a comforting thing at this point.

Remember how about I stated I’m no programmer? I was stuck at this point. Luckily, I have what we commonly refer to as ‘problem-solving skills’ so I came up with a few more plans. You may laugh, you may cringe, but at this point they seemed worth a shot.

Next up on the list: re-installing MT, then dropping the old data directory, db, on top of the new install in hopes that the interface would just recognize the old data and think everything was okay. But I couldn’t login to Movable Type after doing it. I reverted back to the freshly installed db directory, and was able to login fine. I tried selectively dumping a couple of the larger .db files into the new directory, but had no luck doing that either.

DNS Trickery

So I still had the archives, but no way of getting at them. Hmm. I was smart enough not to cancel my prior hosting account, so I grit my teeth and moved my DNS back to the old server.

A day or two of waiting for propogation, then I was able to log in to my old MT interface, manually export my entries and comments thanks to Six Apart’s clear thinking about not locking users in, save my customized templates, then switch DNS back to the new server.

At this point the cards started stacking back in my favour again. My new server gives me a static IP, so I was able to point my copies of Firebird and Safari toward it without waiting for the propogation. I set to work getting the old entries imported into my fresh install, and added my templates through the interface.

Which is not to say this process wasn’t without its share of trouble — even though I temporarily pointed Movable Type toward the IP instead of the domain, I wasn’t able to access everything. When saving entries or comments, for example, the refresh would go to a non-existent page on mezzoblue.com. This was only a minor inconvenience though, since the data was saved regardless. While waiting for the rest of the world to catch up, I was hard at work plugging the holes and making sure things would be up and running by the time the DNS change went through.

At this point I made a valiant attempt to switch from Movable Type’s default Berkely DB system to MySQL, since that was the other half of the equation. However, since I needed a quick fix, my inexperience with the latter got in the way and I eventually conceded that to a later date. Bigger fish to fry, after all.

Summary

So while I showed some foresight, the process was hardly as smooth as it could have been. For a few days, I wasn’t able to do much in the way of posting new content, and a static page greeted visitors to the site. Effectively, I was knocked offline as I waited for the jump to and from and then to my new host, although during that time most were still able to access one server or another.

I’ve been on Apache for two months now, and I couldn’t see myself going back. I haven’t even begun to scratch the surface of the things I can do, but it’s comforting to know that if I need to, they’re there. At least I’m in the happy spot of being able to blame shortcomings on lack of brainpower, rather than lack of horsepower. That, in my books, is the easiest of the two to fix.


Reader Comments

azure says:
December 02, 04h

Wow, now *that’s* determination! Thanks for the links to the books you used, I’ve made note of them. I’ve only recently started delving into PHP and really enjoy all the tricks that can be pulled off with it.

As for MT, it is, by far, one of the best cms’ out there. I’ve set up quite a few people with MT, not only for their weblogs but for their static websites as well. The template modules alone are a godsend, especially for sites that have multiple designs (“skins”). With MT includes you can just edit a module and rebuild to facilitate a site-wide change, rather than going into each design’s index file and rebuilding and rebuilding! :)

Enough of my blabbering, I feel your pain regarding that MT install & MySQL. About two months after switching to MT, I nosed up my db and had to start all over, no backups, nothing. You’re lucky you had backups of everything! In either case, obviously you did a great job. And will know what NOT to do should you EVER have to do anything like that again!! ;)

December 02, 05h

Hmmm. Such a different experience than my own. Must be why I feel entirely guilty that I just read though your experience with some amusement. I don’t know why things happened to swing the right direction for me, or how I found the right spot in my O’Reilly books each time.

Aside from a few parsing error glitches in home grown PHP functions early on, the most difficult part of my switch was getting MT installed to run under cgiwrap (more secure, and creates files under my username, rather than user “nobody”).

For a designer fumbling their way through scripting and programming, there’s somthing about all the documentation, modules, and add-ons for Apache/PHP/MySQL that hits home more than the closed-loop MSDN stuff.

Thanks for writing up your process. It certainly puts mine into perspective.

December 02, 09h

I’ve missed the joy of an MicroSoft -> Apache transfer, although I have evolved from mostly perl to all PHP development, and have experienced none of the problems above installing MT (maybe lucky, but also I have my own servers at the day job).

Since you mentioned using an iBook, there is an other plus- under OSX you can run Apache, PHP, mySQL all locally on the desktop (as well as phpMyAdmin to do database chores)- I can develop and test anything on my laptop I run on the main server before deploying it, and can even do it w/o a network connection.

Key resources have been the PHP and mySQL install packages from Marc Linyage:
http://www.entropy.ch/software/welcome.html

4
Woody says:
December 02, 10h

I feel your pain. I’d like to move away from ASP as well. Why not an all PHP solution (rather than perl with MT) such as Word Press (http://wordpress.org/ ).

5
Woody says:
December 02, 10h

… or why not hosted MT, TypePad.com, http://www.typepad.com.

Dave S. says:
December 02, 10h

I like MT. It’s nice and customizable, I’ve got a few server-side plugins running, and my templates/modules are getting more and more complex. It’s a veritable Swiss army knife of weblogging goodness.

Hosted software like Typepad is good for the masses, but people like me need the advanced stuff having your own server affords. I rely on .htaccess and custom static pages, and I even do some simple PHP scripting here and there.

ste says:
December 02, 11h

I may be going through something similar here at work shortly. Currently our site is hosted across two different servers (the main one being Apache-powered, but without the useful benefits like PHP or custom cgi scripts, and the other an ASP server that seems to become more broken every time I try to use the scripts developed by my predecessor). I’d *love* to move our site to a single Apache server with PHP and cgi so I could manage parts of it with MT, but some of the ASP scripts we currently have running might be a pain to replace in PHP … on the other hand, they’ll probably be just as much a pain to maintain in ASP at the rate they seem to be breaking (particularly with my stunning lack of ASP knowledge).

Next time you change servers (assuming there is a next time), make sure to back up your MT databases ahead of time. (I usually just run an export for each blog and save those as text files.) It really makes moving fairly easy … that way you can also just set up MT from the beginning to work with MySQL and then import your entries right into it. Also make sure you save your templates (remembering your settings and categories is also useful). I’ve moved hosts (as well as started afresh) several times so most of the process is second nature by now.

beto says:
December 02, 11h

Brilliant move, Dave. Long ago I was convinced to switch over to PHP/MySQL because that’s what all cool kids do (I’m only half-joking here). I’ve changed server hosts several times over the years and, while far from being an experience without its hitches, I must confess I’ve learned quite a bit from such moves. I can’t call myself a programmer either, but there’s something in PHP code that has a sort of good vibe feel to it, as opposed to ASP code which looks and feels ugly.

My workplace, however, is Microsoft-land and still relies heavily in IIS, ASP and other inventions from Uncle Bill. It is tough to convince the upper echelons of the existance of better -and cheaper- alternatives when you are not in the decision maker role.

Geof says:
December 02, 11h

The irony of Matt Mullenweg hosting you with an MT install isn’t lost on me. ;)

December 03, 01h

Anyone who can move away from ASP 3.0 to almost anything else is doing themselves a favor. Moving over to PHP is even better because it is almost guaranteed to be around for a long time. Glad to see you stuck through the difficult transition.

11
Kishor Gurtu says:
December 03, 02h

Check out these hosting plans (unlimited traffic at an unbelievable price). All the plans support ASP.NET and PHP

http://www.securemate.com/windows-asp-hosting.asp

Manuzhai says:
December 03, 03h

It’s so refreshing to see some people who are not bashing PHP. :) A lot of people around the ‘net keep looking at its shortcomings, but it’s a really great tool. Hope you have fun with it.

13
jens persson says:
December 03, 07h

Just for the record (and google) there is the program asp2php http://asp2php.naken.cc/ that might help in the convertion. I’m a happy U*IX only person and the only convertion from asp I have done was to static html with wget, html-tidy and vi :-) so how well it works I can’t tell.

And for a bonus bug report: When trying to post without a email address filled in, you get to page without stylesheets.

Matt says:
December 03, 11h

I tried using the asp2php program before when converting a rather large custom CMS from ASP to PHP and found it to be close to useless. What I found the best way to be is to just move the database over and then rewrite the functionality in PHP, using the ASP as a logic guide when needed. It took longer but it also gave me a chance to clean up a lot of (probably machine-generated) mess in the ASP code and redo the program in a more robust manner. In hindsight I’m glad the converter didn’t work. :)

And Dave, always glad to help.

15
Mikael says:
December 03, 12h

If you’re in a situation where you have a web server fully operational and set up for a certain domain, but the DNS actually pointing to a different server, you can browse your old stuff without actually moving the DNS back and forth by editing the file c:\winnt\system32\drivers\etc\hosts on the workstation you are using for web browsing.

If your IIS server would have been on IP 192.168.0.1 and your Apache on IP 10.0.0.1, you could have had two lines in that file:

192.168.0.1 www.mezzoblue.com
#10.0.0.1 www.mezzoblue.com

Comment out with a # the line you don’t want to use. When you’re done, comment out both lines.

Ian Lloyd says:
December 03, 12h

I still have to go throught the pain, to a certain extent. Now that I have Apache and PHP working, I can begin to convert Accessify to PHP. It’s already coming along - and like you, it’s mainly include files (there is still some prgrammatic stuff happening, like the auto breadcrumb trail and, shamed as I am to admit, there’s some browser sniffing … please don’t shoot me, it’s for the right reasons!).

My difficulty will be when I get to converting the tools and wizards section from ASP to PHP - that’ll be a real head-scratcher!

Anyway, I’m taking Ullman’s MySQL Visual Quickstart with me on my travels, so the database driven side of things can also be converted at some point. Of course, given that I will be taking a year out on the road, it’s questionable when I’ll be in a position to upload a freshly PHP’d version of the site!

dusoft says:
December 03, 12h

Congratulations on that.

I started with PHP/MySQL in 2000 and that’s the best thing for the online interactive websites at the moment.

I have developed Absolut Engine - news publishing system that can be found at http://www.absolutengine.com

It’s also very light system in comparison with other CMS that offer ‘complex’ solutions - but who need it complex?

December 04, 06h

PHP and MySQL are great. You certainly can’t beat the cost! But I’d hardly start bashing ASP. I’ve been using it and MS SQL Server for years and have found it to be just as fast and stable as any other platform. Of course, YMMV. :)

Ed says:
December 04, 08h

Jonathan, thanks for speaking up. While I think it’s great that one can make a switch from ASP to PHP that’s not to say that ASP isn’t useful/reliable. As one who would consider himself a programmer with a design degree, I’ve enjoyed developing in ASP for many years. It’s like the MAC vs PC battle - % vs $.

Gavin says:
December 06, 07h

Nice work - I actually went the other way and created an asp version of my site recently as I needed to do something in ASP to demonstrate a few bits and pieces.

All I can say is, after working with PHP for so long it was kind of painful (needless to say, I’ve stuck with the PHP version ;))

Jerrett says:
December 08, 05h

I’ve been working on a PHP Website Framework to handle the split of logic and markup, as well as splitting databasing etc off into their own little worlds - I realize there is a lot out there, but all the stuff I’ve seen is overcomplicated and/or more along the lines of a “CMS”..

The method I’m using utilizes php as the templating language, since PHP does such a wonderfull job of that ( why the *@#% people create things like smarty to re-implement what php already does only with limitations, is beyond me…. this comes from after implementing a rather large scale project in smarty, only to have to rip smarty out later after re-evaluation) - but still provides the neccesary split of using “templates” to remove html from the .php files… as well as allowing you to create a layout template/wrapper, to avoid the ugly trap of include(“header.php”) / include(“footer.php”); that people tend to get locked into when getting into PHP (or any server side language)

What this really accomplishes in plain speak, is that it really allows you to focus on three *seperate* things while designing a webpage. One being the backend code, which does it’s little thing, gets you your data etc - The second being the markup - not the design, but writing the actual markup of the page. Last of all, the design/css. I’ve found through this that keeping these three things seperate makes worlds of diffrence, not only in ease of development, but it makes it more enjoyable too, as things don’t get all cluttered and hard to locate.

Sooner (hopefully rather than later), there will be downloadable versions of this for people to play with - I have to get some feedback from a few friends first tough :)

In the PHP “vs” ASP front, I have to say I’m impressed with what i’ve seen of .net - however, call it loyalty, familiarity, or simply a bad taste in my mouth from previous versions of windows/asp, I’ll be sticking with PHP, and waiting eagerly for PHP5 :D

Anyone interested in reading more about php templating, a guy named ‘saberworks’ wrote a good article on it here: http://www.liquidpulse.net/articles/332

Chris says:
January 02, 03h

Jerrett, I’ve found this article (http://www.sitepoint.com/article/1218) at Sitepoint very influential when evaluating template systems.