Setting Up Your Own Web Server on a Windows Machine (Apache HTTP Server)

This is a step-by-step tutorial that teaches you how to install a web server under Windows XP. The tutorial is for those who want to have a web server running on their local machine as a test server but don't know how to get started. In addition to the web server, this tutorial will also guide you how to manually install PHP 5 and MySQL 5 (without installers).

Table of Contents

Motivation

Suppose you are learning PHP and you want to run some test scripts without bothering to buy a hosting plan, or you want to run some server side applications such as WikiFilter on your personal computer, or you are just curious about how stuff work, this tutorial is for you! Here are some unique advantages of private web server:

  • You can do it with open-source softwares, so it's free (Apache HTTP server, PHP 5 and MySQL are all open-source).
  • You can develop web applications on top of it without paying extra fee.
  • You can install and run various third party web based applications such as web based forum on your personal computer without actually connecting to the internet.

Installing Apache HTTP server

  1. We will use the latest version of the HTTP server from Apache. As the time of writing, the latest version is 2.2.4. Download Apache 2.2.4 here.
    If above download link is unavailable, you can always download a copy from http://httpd.apache.org/. Go to the download page, and choose Win32 Binary (MSI Installer).
  2. Open the installer you just downloaded, click Next. Accept the License Agreement, click Next. Read through the information if you want, and click Next.
  3. You end up at this screen: apache installer
  4. The default value should work. If it doesn't, enter localhost for both Network Domain and Server Name, and enter anything you want for Administrator's Email Address.
    Note: The auto populated values in the input boxes shown in above screen shot can be different from yours depending on the setting of your system.
    For the Install Apache HTTP Server 2.2 programs and shortcuts option, select the first option, which tells Apache to listen on port 80. You can change the listening port later easily in the configuration file. Click Next to proceed to next step.
  5. Select Typical for setup type. Click Next. apache installer
  6. Change the installation directory if you wish. Click Next. apache installer
  7. Click Install and finish the remaining installation steps.

Running Apache Server as a Windows Service

If you followed the installation procedures above, you should have Apache server installed as a Windows service. You can check this by opening up Apache Service Monitor from your Windows XP start menu: Start -> All Programs -> Apache HTTP Server 2.2.4 -> Control Apache Server -> Monitor Apache Servers.

If it is not there, you can go to the bin directory of your apache installation directory and execute it directly. By default, the path to Apache Service Monitor is C:\Program Files\Apache Software Foundation\Apache2.2\bin\ApacheMonitor.exe. apache monitor

Skip the section below if you see Apache2 under the Service Status window of your Apache Service Monitor.

Troubleshooting

In case that Apache service is not shown in the service monitor, you need to install the service manually. Don't be panic, it's really easy. Open up a command prompt window and navigate to the bin directory of your apache installation (default is C:\Program Files\Apache Software Foundation\Apache2.2\bin), and type the following command:

httpd -k install
If the system can not find httpd, in other words, httpd.exe does not reside in your Apache's bin directory, try:
Apache -k install
You should receive notification from Apache that Apache service has been successfully installed. install command prompt

Testing Your Apache Installation

Fire up your favorite browser and navigate to http://localhost/ or http://localhost:port/ if you are using listening port other than port 80. For instance, if you are using port 8080, type http://localhost:8080/. You should see a welcome page.

welcome page

Note: Your welcome page might look different if you are using Apache other than version 2.2.4.

The web page displayed above is an index page, which can be found at $PATH_TO_APACHE$\htdocs. $PATH_TO_APACHE$\htdocs, or DocumentRoot, is the default location where your web pages will be stored. Detailed instruction on how to change index page and DocumentRoot can be found here: DocumentRoot and Index Page.

Configuring Apache (Optional)

Change Apache's configuration can be done in the following steps:

  • Locate configuration file [PATH_TO_APACHE]\conf\httpd.conf and open it in a text editor.
  • Locate the configuration setting. For example, ServerRoot "C:/Program Files/Apache Software Foundation/Apache2.2".
  • Apply changes.
  • Restart Apache so changes can take effect.
  • Note that anything after "#" sign are comments, they have no effect on Apache's configuration.

Below are some common settings you might want to change:


Default Page / Index Page

This option tells Apache which file to serve when there is no file name in a requested URL. For example, consider the request URL is http://localhost/, since there is no web page specified, Apache will serve the first matched index page specified in your configuration file. Therefore, the actual served web page is http://localhost/index.html. You might want to add index.php here if you are going to run PHP with Apache.

Changing Apache's Listening Port

Changes to this setting is not required unless you want to change the port of which apache is listening to.

Currently the port value is set to 80, which is the default port for HTTP protocol. That means you can access your web site from either http://localhost/ or http://localhost:80/.

If you have changed this listen port to 12345, the corresponding web site address would be http://localhost:12345/.

Changing Document Root

You can change the location where Apache stores your web pages by modifying these two lines:

Suppose you want to place your HTML files under a folder called "www" under C: drive, you can make the following changes:

and

Customizing Host Name (Optional)

Do you know you can name your hostname to whatever name you want? It's really simple. If you don't like localhost to appear everywhere in your URL, you can add your own mapping to Windows' hosts file. Note that this file does not contain any file extension. Go to %systemroot%\system32\drivers\etc\ and open the file hosts in any text editor. Add a new mapping to address 127.0.0.1, give it a creative name:

You can now access your site from mysite.com.

custom-hostname.gif

Next: Installing PHP

4 Comments Setting Up Your Own Web Server on a Windows Machine (Apache HTTP Server)

  1. angie lines

    Re: configuring Apache server. Just curious. I am a total n00b. What should I change and how should I change it in order for flash vids to display properly on my page.

  2. Pingback: How to install Apache HTTP Server | How Install

Comments are closed.