How to install Apache web server on Windows

  1. Step 1: Download the package file
  2. Step 2: Extract the files
  3. Step 3: Configure Apache
  4. Step 4: Change the Document Root (optional)
  5. Step 5: Test your installation
  6. Step 6: install Apache as a Windows service
  7. Step 7: Test the Web Server

Step 1: Download the package file

We’re going to use the unofficial Windows binary from Apache Lounge. This version has performance and stability improvements over the official Apache distribution, it’s provided as a manually installable ZIP file from www.apachelounge.com/download/.

Step 2: Extract the files

We’ll install Apache in C:/Apache24, so extract the ZIP file to the root of the C:/ drive. Apache can be installed anywhere on your system, but you’ll need to change SRVROOT configuration to point to your unzipped location — suh as E:/Apache24.

Step 3: Configure Apache

Apache is configured with the text file conf/httpd.conf contained in the Apache folder. Open it with your favorite text editor.

Note that all file path settings use a forward slash (/) rather than the Windows backslash. If you installed Apache anywhere other than C:/Apache24, now is a good time to search and replace all references to C:/Apache24.

There are several lines you should change for your production environment:

  • Line 60, listen to all requests on port 80:

    1
    Listen *:80
  • Line 162, enable mod-rewrite by removing the # (optional, but useful):

    1
    LoadModule rewrite_module modules/mod_rewrite.so
  • Line 227, specify the server domain name:

    1
    ServerName localhost:80
  • Line 224, allow .htaccess overrides:

    1
    AllowOverride All

Step 4: Change the Document Root (optional)

By default, Apache returns files found in its C:/Apache24/htdocs folder. It’s good to use a folder on an another drive or partition to make backups and re-installation easier. For the purposes of this example, we’ll create a folder called D:WebPages and change httpd.conf accordingly:

Line 251, set the root:

1
DocumentRoot "D:/WebPages"

Line 252:

1
<Directory "D:/WebPages">

Step 5: Test your installation

Your Apache configuration can now be tested. Open a command box (Start > Run > cmd) and enter:

1
2
3
4
# navigate to Apache bin directory
cd /Apache24/bin
# Test httpd.conf validity
httpd -t

It should say “Syntax OK”. If not, correct any httpd.conf configuration errors and retest until none appear.

Step 6: install Apache as a Windows service

The easiest way to start Apache is to add it as a Windows service. Open a new command prompt as administrator, and enter the following:

1
2
cd /Apache24/bin
httpd -k install

Open the Control Panel, Administrative Tools, then Services and double-click Apache2.4. Set the Startup type to “Automatic” to ensure Apache starts every time you boot your PC.

Alternatively, set the Startup type to “Manual” and launch Apache whenever you choose using the command “net start Apache2.4”.

Step 7: Test the Web Server

Create a file named index.html in Apache’s web page root (either htdocs or D:\WebPages) and add a little HTML code:

1
2
3
4
5
6
7
8
<html>
<head>
<title>Testing Apache</title>
</head>
<body>
<p>Apache is working!</p>
</body>
</html>

Ensure Apache has started successfully, open a web browser and enter the address http://localhost/. If all goes well, your test page should appear.

In general, most problems will be caused by an incorrect setting in the httpd.conf configuration file. Refer to the Apache documentation if you require further information.