2007-11-02, , , Comments

Virtual hosting problems

A colleague, call him Lem E Tweakit, was suffering from code-rage. I could tell from the way he was shoving his mouse around, hammering the keyboard and muttering.

“Anything I can help with?”

“Yeah, maybe. Have you ever set up Apache on Windows?”

I have, but never to do more than serve static files, run CGI scripts, that sort of thing. Given the choice, I’ll use a Unix-based system for a web server every time, and I prefer lighttpd, but anyway, what’s the problem?

Virtual hosts weren’t working, Lem said. He’d googled around, found some instructions written up by someone who’d overcome a similar problem, followed the instructions, found they didn’t work, googled a bit more, found some slightly different instructions, they didn’t work either … and now he was stuck in a cycle of tweaking httpd.conf, restarting the web server, refreshing his browser to see if it had worked, googling.

Like he said, virtual hosts weren’t working! Were they even supposed to work on Windows?

Search the Web

In a recent post on his artima weblog Andy Dent suggests that when interviewing programmers, you should test their ability to search the web. He adds you should consider training existing employees in this skill.

I’ve got mixed feelings about this. Certainly you shouldn’t expect candidates to carry everything around in their heads (though I would expect someone who puts “Experienced C Programmer” on a CV to be able to write syntactically correct C without access to a reference — it’s alarming how many can’t!)

Read the Manual

What I consider important is how exactly someone goes about finding information. The web search is a great tool but it shouldn’t always be the first one we reach for. Continuing our earlier example, for C the most important reference has to be K & R, and I’d expect any serious C programmer to know and use this book. And Unix programmers call on man and info even if the search quality for these references isn’t quite up to google’s standards.

C and Unix are showing their age, though. What about something more up to date, something more closely aligned to the internet? Python, say, to pick something I claim to know about.

Again, if I need Python help I don’t start with a web search, even though a lot of the time I do end up referring to web pages. For simple queries I try help() in an interpreted session. For full answers, I point my web browser at the official documentation, which, incidentally, I have bookmarked to use a location on my hard-disk — a location which came as part of my standard Python installation. This means I have direct access to the documents on- or off-line, it’s fractionally quicker than going to docs.python.org, and I’m guaranteed to get the documentation for the Python version I’m using. If I still can’t find what I’m looking for then there are a number of options: the Python Cookbook, a web search, email a friend, comp.lang.python.

If it’s a non-standard Python library I’m using (the Python Imaging Library for example) then again I’ll try the official documentation for that library first; and if this documentation doesn’t help then I probably won’t be using the library much longer (the PIL documentation is fine, I use it all the time).

No, Search the Web

I won’t pretend I always read the manual and never search the web. Far from it. On many occasions a web search turns up something that’s better than the official manual. On other occasions I want a quick fix: perhaps I’m using a technology I really don’t care much about, and am therefore reluctant to invest any great effort in. Vi for example, some Java framework, or Open Office.

Does Apache httpd fall into this category? Of course not. It may not be my web server of choice, but it’s the world’s web server of choice, and definitely something a programmer should know about.

Apache Virtual Hosts

I watched Lem more closely. The first thing I noticed was that when he restarted Apache — by clicking an icon — a console window transiently appeared, and I’m pretty sure there was an error message in that window. What was it trying to say?

Lem pulled up the server error log. Sure enough, it recorded an error found in the configuration file. Not a fatal error, otherwise the server wouldn’t have started, but a strong indication something wasn’t right.

“I know, I’ve tried googling for that, but …”

I’d also noticed an icon linking to the online Apache documentation: look, there, right next to the “Start Apache” icon!

We clicked it and found ourselves on the Apache HTTP Server documentation page.

Apache 2.2 documentation page

As you can see, there’s a prominent search widget at the top of the page. Lem instinctively typed “Virtual Hosts” into the text field and clicked the button.

“It’s just a google search,” he said, disgusted. Hadn’t Google been letting him down all morning?

Not quite! It’s actually a google site search — you do know google can return you search results within a specific site? As it happened, the first hit from this search was the one we wanted, one we should have spotted on the front page of the documentation if we’d not been diverted by the search button.

After about 5 minutes of careful reading we’d fixed httpd.conf, eliminated the warning, and virtual hosting was working.

Find out about Lem E Tweakit, including address and salary details.