Wednesday, October 17, 2012

WAMP step 1: the Apache httpd server

Our goal in this process is to set up WordPress to serve the test content of a website and blog. Therefore the very first thing we are going to need is a web server.

I should say at the beginning that you don't need a web server to test basic web pages, you can write HTML files with any text editor, and then point your web browser at the file. You can teach yourself a lot of HTML and client-side JavaScript programming in this way. I think it is better to learn the fundamentals of how web pages work by typing it out for yourself instead of starting with a web development environment - you really understand what is going on.

Web servers deliver content to browsers. This content (web pages, music, images, etc.) is either a file on your machine's hard drive, or data stored in a database (on the hard drive). If it is data from the database, then a program (a script) must be run first to turn it into a document that is served out by the web server.

So even before we set up our Apache web server, we need to set up some space on our hard drive where this content will live. Importantly, we want this space to be independent of the Apache server file structure, so that we can back it up separately, and update Apache if necessary without moving our content. We could even change web servers entirely and our content would still be in the same place.

1 - Create your content file directories

Use Windows Explorer to create a 'sites' directory on C:. You can vary the name and the drive letter, just be consistent as you follow all of the instructions.
Within C:\sites, create a directory for your first website, 'example'.
Within C:\sites\example, create a directory for the content of this site, 'content'.

2 - Install Apache

Go to the web site to learn more about the Apache web server. The actual Windows binary files you'll need to install Apache are located at and you should download the MSI (Microsoft Installer) file, such as httpd-2.2.22-win32-x86-openssl-0.9.8t.msi.
Double clicking on the .msi file after it is downloaded will start the installation process.
Choose "Run". A welcome screen is displayed. Click "Next".

A “Welcome to the Installation Wizard” will appear.  Click “Next”.
Accept the terms of use. Click “Next”.
A notice will appear. Click “Next”.

We will be using the Apache server to serve documents off of the same machine as the browser. In the geek speak of the web, this self reference is called the "localhost". You'll use this term in the next part of the install.

You will be prompted to enter your server’s information.  Use the following:
Network Domain: localhost
Server Name: localhost
Administrator’s Email Address:

Select “for All Users, on Port 80, as a Service – Recommended”.
Click “Next”.

For all Users is self explanatory.

As a service means that the software will run without any windows open on your desktop, and will be started automatically each time you reboot your machine. You interact with services using the Microsoft Management Console (Control Panel/System and Security/Administrative Tools/Services).

Port 80 is the internet standard for http protocol traffic. Historically, as different kinds of computer communication were developed, each claimed a specific port for itself. Another example is the area of online games, where each uses specific, agreed upon ports to communicate. The web is so ubiquitous at this point that firewalls will always leave port 80 open, even as they disallow traffic on most ports to help keep your PC secure.

A side effect of this is that some applications, such as Skype, will try to use port 80 for themselves. Skype figures that a desktop PC used for Skype is unlikely to run a web server, so it grabs 80 for itself. This means that in the situation we are in right now, Skype is probably going to cause some problems. As a way to head off these problems, open Skype and go to Tools/Options/Advanced/Connection and uncheck the box that is labelled "Use port 80 and 443 as alternatives for incoming connections". Save, quit Skype and restart it.

Select “Typical” setup type. Click “Next”.
The install path should look like:
C:\Program Files\Apache Software Foundation\ApacheX.X\
Click “Next”.
Click “Install”.
Wait for installation to complete. Click “Finish”.
Type http://localhost in the address bar of your browser and make sure it displays “It works!”. "It works!" is the content of a very simple HTML file that Apache installed on your hard drive as part of the installation process. Seeing this displayed is proof that Apache is working correctly.


Of course, it might not be working correctly. We tried to head off the most common reason (for desktop PCs, anyway) by changing Skype's settings. Another possibility is that you are running an anti-virus program that won't let Apache use port 80, or that another program is already using port 80 (not Skype). Try checking your anti-virus program documentation for how to allow a web server to run, and to see if any other program is using port 80, follow some good directions on using netstat for this purpose.

Installing Apache means you also got a tool that lives in the system tray, the Apache Monitor. You can use this tool instead of the Services console I mentioned earlier to stop, start, and restart Apache. However, both of these UI tools will not give you the best error messages when something is going wrong with Apache. For that, you will have to use the command prompt.

To use the command prompt, open it with Startup/All Programs/Accessories/Command Prompt. I first change directories:
cd C:\"Program Files (x86)"\"Apache Software Foundation"\Apache2.2\bin

Assuming you've got the quotes and spelling correct, you are now in the directory where the web server executable file is kept. At the prompt, type


This is the file name of the Apache web server. If it starts correctly, you won't get another prompt (because the program is running). If there is a problem, you'll get a much more informative error message and a new prompt.

In subsequent steps of installing the WAMP stack, it will be necessary to edit some of Apache's configuration files. Since these are in the "Program Files (x86)" file structure, Windows has automatically made them write protected. Before editing them the first time, use Explorer to open their properties, go to the Security tab, click Edit, choose Users in the top list, and check Modify in the lower pane. Click OK twice to close the windows. Now you can edit and save this file. Keep track of which files you've expanded the permissions on, so that you can go back at the end and restrict them again. As an alternative, log in to your machine as Administrator for this whole long process.

No comments: