November, 2003

Apache is my new best friend

I love Apache. You can run it on Linux or Windows. You can run it on your PC so people around you can see your code as you create it (dang, does that make you look good or what?). You can configure it to mimic the settings on your web hosting, so that all you have to do is upload the code once completed and it works like a voodoo charm. You can host hundreds of sites simultaneously with it. It's one of the most wonderful pieces of software ever written. I adore it. Soon, you will too.

Setting it up on a Windows PC is quick and easy. Just go to the site and download the executable. Run it. (You can pick either the Windows .msi installer version from the mirror site, or the full executable.) Your index.html file (and all the other code) will live in a folder called c:\program files\apache group\apache2\htdocs\. When you put the IP address of your computer into your browser window, you'll see your website. Incredibly useful at work when you want to share things or display web-based information. Or when you're not at work. Just be careful that your PC is hardened (i.e behind a firewall)... you're advertising that you're serving web pages; that can make you a target.

If you really want to get fancy about things, such as enabling server side includes, just modify the httpd.conf file that's located in c:\program files\apache group\apache2\conf\. Add these 2 sections to the httpd.conf file:

  1. Under #     Options Indexes FollowSymLinks, put:
    Options Indexes FollowSymLinks Includes
    Options +Includes
  2. Under # To parse .shtml files for server-side includes (SSI):
    AddType text/html .shtml
    AddOutputFilter INCLUDES .shtml
    AddType text/html .html
    AddOutputFilter INCLUDES .html
    AddType text/html .htm
    AddOutputFilter INCLUDES .htm

Then make a file called .htaccess. This is separate from the http.conf file. You can make it with Notepad. Windows won't let you make a file that only begins with a dot, but you can always open up a DOS window and rename the file. (Run cmd.exe, then navigate to where the file is. Type "rename whateveryourfilenameis.txt .htaccess"; leave a space between the two filenames, and press enter.) Voila! Instant .htaccess file. Open it up in Notepad, and put these two lines of text in it:

  • AddType text/html .htm
  • AddHandler server-parsed .htm

And that's it! (Well, you could repeat the same lines for .html files if you were so inclined.) Save, close, and now your server side includes will work quite nicely. You can customize this file to do other things, but configuring for server side includes is 99% of what people ever do with this, so now you have it. The syntax of a server side include command within your HTML is <!--#include virtual="yourfilename.htm" -->don't forget that there is a space between the last quotes and the two dashes. This is so that when you have an HTML document and you want to display the contents of another document within it, you simply summon that other file using the pound-include-virtual command. This means you can make a top navigation bar for your entire site in one file, and display it throughout your entire site using this include command in every page. Should there be changes to your navigation, you only have to change the one file that has the navigation - not the entire site. This avoids Much Heartburn and is a Thing of Beauty.

Soon you will wonder how you ever lived without this. It's that awesome. Try it today!