### Apache HTTP Server Version 1.3

# Using Apache With Microsoft Windows

This document explains how to install, configure and run Apache 1.3b6 and later under Microsoft Windows. Please note that at this time, Windows support is entirely experimental, and is recommended only for experienced users. The Apache Group does not guarantee that this software will work as documented, or even at all. If you find any bugs, or wish to contribute in other ways, please use our bug reporting page.

Warning: Apache on NT has not yet been optimized for performance. Apache still performs best, and is most reliable on Unix platforms. Over time we will improve NT performance. Folks doing comparative reviews of webserver performance are asked to compare against Apache on a Unix platform such as Solaris, FreeBSD, or Linux.

Most of this document assumes that you are installing Windows from a binary distribution. If you want to compile Apache yourself (possibly to help with development, or to track down bugs), see the section on Compiling Apache for Windows below.

- Requirements
- Downloading Apache for Windows
- Installing Apache for Windows (binary install)
- Running Apache for Windows
- Using Apache for Windows
- Running Apache for Windows from the Command Line
- Signalling Apache when running
- Compiling Apache for Windows

## Requirements

Apache 1.3 is designed to run on Windows NT 4.0. The binary installer will only work in Intel processors. Apache may also run on Windows 95 and Windows NT 3.5.1, but these have not been tested. In all cases TCP/IP networking must be installed.

If running on Windows 95, using the "Winsock2" upgrade is recommended but may not be necessary. If running on NT 4.0, installing Service Pack 2 is recommended.

## Downloading Apache for Windows

Information on the latest version of Apache can be found on the Apache web server at http://www.apache.org/. This will list the current release, any more recent alpha or beta-test releases, together with details of mirror web and anonymous ftp sites.

You should download the version of Apache for Windows with the `.exe` extension. This is a single file containing Apache, ready to install and run. There may also be a `.zip` file containing the source code, to compile Apache yourself. (If there is no `.zip` file, the source will be available in a `.tar.gz` file but this will contain Unix line endings. You will have to convert at least the `.mak` and `.dsp` files to have DOS line endings before MSVC will understand them).

## Installing Apache for Windows

Run the Apache `.exe` file you downloaded above. This will ask for:

- the directory to install Apache into (the default is `\Program Files\Apache Group\Apache` although you can change this to any other directory)
- the start menu name (default is "Apache Web Server")
- the installation type. The "Typical" option installs everything except the source code. The "Minimum" option does not install the manuals or source code. Choose the "Custom" install if you want to install the source code.

During the installation, Apache will configure the files in the `conf` directory for your chosen installation directory. However if any of the files in this directory already exist they will not be overwritten. Instead the new copy of the corresponding file will be left with the extension `.default`. So, for example, if `conf\httpd.conf` already exists it will not be altered, but the version which would have been installed will be left in `conf\httpd.conf.default`. After the installation has finished you should manually check to see what in new in the `.default` file, and if necessary update your existing configuration files.

Also, if you already have a file called `htdocs\index.html` then it will not be overwritten (no `index.html.default` file will be installed either). This should mean it a safe to install Apache over an existing installation (but you will have to stop the existing server running before doing the installation, then start the new one after the installation is finished).

> Important note for 1.3b6 installs: the above only applies for 1.3b7 and later. In 1.3b6 the installer would overwrite any existing `httpd.conf`, `access.conf`, `srm.conf` or `mime.types` files in the `conf`, and will also overwrite your `index.html` file in the `htdocs` directory. You should copy these files or directories before installing Apache 1.3b6 or install into a new directory.

After installing Apache, you should edit the configuration files in the `conf` directory as required. These files will be configured during the install ready for Apache to be run from the directory where it was installed, with the documents served from the subdirectory `htdocs`. There are lots of other options which should be set before you start really using Apache. However to get started quickly the files should work as installed.

## Running Apache for Windows

There are two ways you can run Apache:

- As a "service" (available on NT only). This is the best option if you want Apache to automatically start when you machine boots, and to keep Apache running when you log-off.
- From a console window. This is the only option available for Windows 95 users.

To start Apache as a service, you first need to install it as a service. Run the "Install Apache as Service" option from the Start menu. Once this is done you can start Apache by opening the Services window (in the Control Panel), selecting Apache, then clicking on Start. Apache will now be running in the background. You can later stop Apache by clicking on Stop. As an alternative to using the Services window, you can start and stop Apache from the control line with

      NET START APACHE
      NET STOP APACHE

To run Apache from a console window, select the "Apache Server" option from the Start menu. This will open a console window and start Apache running inside it. The window will remain active until you stop Apache. To stop Apache running, see Configuring Apache for Windows Apache is configured by files in the `conf` directory. These are the same as files used to configure the Unix version, but there are a few different directives for Apache on Windows. See the Apache documentation for all the available directives.

The main differences in Apache for Windows are:

- Because Apache for Windows is multithreaded, it does not use a separate process for each request, as Apache does with Unix. Instead there are usually only two Apache processes running: a parent process, and a child which handles the requests. Within the child each request is handled by a separate thread.

  So the "process"-management directives are different:

  MaxRequestsPerChild - Like the Unix directive, this controls how many requests a process will serve before exiting. However, unlike Unix, a process serves all the requests at once, not just one, so if this is set, it is recommended that a very high number is used. The recommended default, `MaxRequestsPerChild 0`, does not cause the process to ever exit.

  ThreadsPerChild - This directive is new, and tells the server how many threads it should use. This is the maximum number of connections the server can handle at once; be sure and set this number high enough for your site if you get a lot of hits. The recommended default is `ThreadsPerChild 50`.

- The directives that accept filenames as arguments now must use Windows filenames instead of Unix ones. However, because Apache uses Unix-style names internally, you must use forward slashes, not backslashes. Drive letters can be used; if omitted, the drive with the Apache executable will be assumed.

- Apache for Windows contains the ability to load modules at runtime, without recompiling the server. If Apache is compiled normally, it will install a number of optional modules in the `\Apache\modules` directory. To activate these, or other modules, the new LoadModule directive must be used. For example, to active the status module, use the following (in addition to the status-activating directives in `access.conf`):

          LoadModule status_module modules/ApacheModuleStatus.dll

  Information on creating loadable modules is also available.

- Apache can also load ISAPI Extensions (i.e., Internet Server Applications), such as those used by Microsoft's IIS, and other Windows servers. More information is available.

## Running Apache for Windows from the Command Line

The Start menu icons and the NT Service manager can provide an simple interafce for administering Apache. But in some cases it is easier to work from the command line.

When working with Apache it is important to know how it will find the configuration files. Apache will try one of the following, in this order.

- A ServerRoot directive via a -C switch.
- The -f switch on the command line.
- The -d switch on the command line.
- A registry entry, created if you did a binary install.
- The server root compiled into the server.

The server root compiled into the server is usually "/apache". invoking apache with the -v switch will display this value labeled as HTTPD_ROOT.

Your current working directory when Apache is started up has no effect on Apache's behavior.

Under windows, when invoked from the start menu or the Service Manager Apache is usually passed no arguments. So using the registry entry is the perfered technique.

During a binary installation, a registry key will have been installed, for example:

      HKEY_LOCAL_MACHINE\Software\Apache Group\Apache\1.3.1\ServerRoot

This key is compiled into the server and can enable you to test new versions without affecting the current version. Of course you must take care not to install the new version on top of the old version in the file system. You can not run two invocations of Apache on Windows simultaneously.

If you did not do a binary install then Apache will in some senarios complain that about the missing registry key. This warning can be ignored if it otherwise was able to find it's configuration files.

The value of this key is the "ServerRoot" directory, containing the `conf` directory. When Apache starts it will read the `httpd.conf` file from this directory. If this file contains a `ServerRoot` directive which is different from the directory obtained from the registry key above, Apache will forget the registry key and use the directory from the configuration file. If you copy the Apache directory or configuration files to a new location it is vital that you update the `ServerRoot` directory in the `httpd.conf` file to the new location.

To run Apache from the command line as a console application, use the following command:

        apache -s

Apache will execute, and will remain running until it is stopped by pressing control-C. (The -s option is not required by Windows 95, but on Windows NT it prevents Apache waiting to see if Apache is running as a service.)

To install Apache as a Windows NT service as follows:

        apache -i

and to remove the Apache service, use

        apache -u

## Signalling Apache when running

On Windows 95 Apache runs as a console application. You can tell a running Apache to stop by opening another console window and running

        apache -k shutdown

This should be used instead of pressing Control-C in the running Apache console window, because it lets Apache end any current transactions and cleanup gracefully.

You can also tell Apache to restart. This makes it re-read the configuration files. Any transactions in progress are allowed to complete without interruption. To restart Apache, run

        apache -k restart

Note for people familiar with the Unix version of Apache: these commands provide a Windows equivalent to `kill -TERM pid` and `kill -USR1 pid`. The command line option used, `-k`, was chosen as a reminder of the "kill" command used on Unix.

## Compiling Apache for Windows

Compiling Apache requires Microsoft Visual C++ 5.0 to be properly installed. It is easiest to compile with the command-line tools (nmake, etc...). Consult the VC++ manual to determine how to install them.

First, unpack the Apache distribution into an appropriate directory. Open a command-line prompt, and change to the `src` subdirectory of the Apache distribution.

The master Apache makefile instructions are contained in the `Makefile.nt` file. To compile Apache, simply use one of the following commands:

- `nmake /f Makefile.nt _apacher` (release build)
- `nmake /f Makefile.nt _apached` (debug build)

These will both compile Apache. The latter will include debugging information in the resulting files, making it easier to find bugs and track down problems.

Apache can also be compiled using VC++'s Visual Studio development environment. Although compiling Apache in this manner is not as simple, it makes it possible to easily modify the Apache source, or to compile Apache if the command-line tools are not installed. Project files (`.DSP`) are included for each of the portions of Apache. To build Apache from the these projects files you will need to build the following projects in this order:

1. `os\win32\ApacheOS.dsp`
2. `regex\regex.dsp`
3. `ap\ap.dsp`
4. `main\gen_uri_delims.dsp`
5. `main\gen_test_char.dsp`
6. `ApacheCore.dsp`
7. `Apache.dsp`

In addition, the `src\os\win32` subdirectory contains project files for the optional modules (see below).

Once Apache has been compiled, it needs to be installed in its server root directory. The default is the `\Apache` directory, on the current hard drive.

To install the files into the `\Apache` directory automatically, use one the following nmake commands (see above):

- `nmake /f Makefile.nt installr INSTDIR=dir` (for release build)
- `nmake /f Makefile.nt installd INSTDIR=dir` (for debug build)

The dir argument to INSTDIR gives the installation directory. The can be omitted if Apache is to be installed into `\Apache`.

This will install the following:

- `dir\Apache.exe` - Apache executable
- `dir\ApacheCore.dll` - Main Apache shared library
- `dir\modules\ApacheModule*.dll` - Optional Apache modules (7 files)
- `dir\conf` - Empty configuration directory
- `dir\logs` - Empty logging directory

If you do not have nmake, or wish to install in a different directory, be sure to use a similar naming scheme.

Before running the server you must fill out the conf directory. Copy the *.conf-dist-win from the distribution conf directory and rename *.conf. Edit the @@ServerRoot@@ entries to your actual server root (for example "C:\apache"). Copy over the conf/magic and conf/mime.types files as well.

### Apache HTTP Server Version 1.3