Apache 2.x Installation on Windows

People new to the fields of web design and development have undoubtedly heard the term "web server", but may be uncertain as to exactly what it means. The term has two meanings, intimately tied to one another: It refers to any software that is capable of accepting HTTP requests from other programs ("clients"), and responding to their requests by outputting ("serving") data of various types. By far the most common example of this is a website server delivering web pages to web browsers. The term "web server" also refers to the computer running such a server program.

There are numerous web server programs available, including Abyss, Apache, IIS, lighttpd, and Nginx. (Google's GWS is not publicly available.) The Apache HTTP Server, commonly referred to simply as "Apache", enjoys the most market share — used by more web servers than all others combined. It has much to recommend it, being a free, stable, and open-source application respected by developers and system administrators alike. The project is supported by the Apache Software Foundation, which is continually maintaining and improving it.

Apache Software Foundation feather
Figure 1. Apache Software Foundation feather

In this article, we will see how to obtain and install the latest stable version of Apache (2.4.3, as of this writing) on a 64-bit Windows 7 machine. The steps for doing so, and the resultant dialog boxes, are likely similar if not identical for Windows Vista, Windows 8, and of course 32-bit Windows 7.

Out with the Old

Prior to installing a new instance of Apache on your computer, it would be wise to first verify that it has not already been installed, and if it has, whether that instance would be adequate for your needs. Apache typically runs as a Windows service, so you should check what Windows services are running, by going to "Control Panel" > "Administrative Tools" > "Services". You should see no Apache entries in the (alphabetical) list.

Windows services with no Apache
Figure 2. Windows services with no Apache

If Apache is present, then you should find out what version it is, because it may be fine for your web development purposes. If it is, then you could avoid the effort and risks involved in replacing it with the latest version.

First look carefully at the Apache entry in the list of Windows services. It probably will take the form of ApacheX.X, where "X.X" is the version/release number, e.g., 1.3 or 2.2. If for some reason the entry does not contain the version number as a suffix, then find the directory where Apache is installed. If Apache had been installed using an MSI installer file, and not a Zip file, then by default that directory will be %ProgramFiles%\Apache Software Foundation\ApacheX.X (where again "X.X" is the version/release number). To determine the directory quickly and with certainty, right-click on the Apache entry in the Windows services list; click the "Properties" menu item; on the "General" tab, note the directory listed in the "Path to executable" field.

Windows services Apache context menu
Figure 3. Windows services Apache context menu

In our example here, the installation directory is C:\_a\Apache. Using a command prompt terminal, go to the bin subdirectory of that installation directory, and enter the command httpd -v.

Apache version
Figure 4. Apache version

In our example, the version is 2.4.3, so I would not bother reinstalling the same version. But if you find an instance that is significantly out of date, or does not support the version of PHP (or any other web scripting language) you want to use, or is older than the version used by the target remote web server, then you should uninstall the current Apache instance. To do so, go to "Control Panel" > "Programs and Features", click on any Apache entry, and click the "Uninstall" link that appears.

If for some reason the installation fails because the server will not stop, then you should be able to stop it manually by going into the aforesaid bin directory, and entering the command httpd -k uninstall.

If there is no such entry for Apache in the list of installed programs, then it was not installed using an MSI file, but instead an archive file (as I will do below). In that case, simply delete that installation directory.

Downloading Apache

Even though the most recent version of Apache is 2.4.3 (as of this writing), it is not available for Windows developers from the official Apache download page, whose most recent Windows binaries are over two years old ("2010-10-19")!

Apache Foundation download page
Figure 5. Apache Foundation download page

This neglect for Windows developers by the Apache Foundation is unexplained.

Fortunately, the good folks at the Apache Lounge have compiled binary packages of the latest version of Apache, and made them available on their Windows 32-bit download page and their 64-bit download page.

Apache Lounge download page
Figure 6. Apache Lounge download page

That page advises one to choose the build with OpenSSL 0.9.8, and not 1.0.1c, if one is using the binaries from the official PHP download page. This is confusing, because where else would one obtain PHP binaries? Also, for 64-bit Windows, there is only one version of the Apache binary package, with no mention of which version of OpenSSL was used in building it.

Click the link for httpd-2.4.3-win32.zip, or httpd-2.4.3-win32-ssl_0.9.8.zip (the latter is built with an earlier version of OpenSSL), or httpd-2.4.3-win64.zip, depending upon your version of Windows. (This article is based on the 64-bit package, but the other versions would probably look identical or nearly so.) Save the installation file on your computer someplace where you can find it.

Installing Apache

Now you are ready to install Apache on your computer. If you intend to use PHP in conjunction with Apache, and you intend to install PHP from a Microsoft Installer (MSI) file, then you should install Apache first, since the PHP installer will look for an Apache instance.

Apache installation files are Zip archive files, and not MSI (Microsoft Installer) files. Hence, using any file archiving program, unzip the Apache installation file that you had downloaded earlier. Find the directory Apache24 (it will contain subdirectories, the first of which is bin), and copy it to whatever installation root directory you prefer — in this example, C:\_a. In addition, you can remove the version/release number (in this case, "24"), since it is unlikely you will need or want to have different versions of Apache present. In this case, the Apache installation directory will be C:\_a\Apache.

The Apache Lounge website states that you must also have the Visual C++ 2010 SP1 Redistributable Package x86 installed. That appears to depend upon the operating system. For instance, on my Windows XP machine, Apache 2.4.3 VC10 Win32 works fine without any 32-bit Microsoft Visual C++ Redistributable Package. On my Windows 7 machine, the 64-bit Microsoft Visual C++ 2005 Redistributable Package was required. On my Windows 8 machine, the Visual C++ 2008 and Visual C++ 2010 packages were pre-installed, and were sufficient for Apache. If you already have Visual Studio installed, then you do not need any additional Visual C++ package. For more information on what happens when the needed DLLs are missing, see the "Troubleshooting" section below.

Each time Apache is started, it obtains critical information from its configuration file, httpd.conf, located in the conf subdirectory. You need to modify that file to get Apache working. But there is always the chance that you might need to restore those initial settings, or consult them later for reference purposes. Therefore, before modifying the original configuration file, save a copy of it or leave the original settings in the file, but commenting them out, by preceding each line with a # character.

Using any text editor, open httpd.conf, locate the line that defines the value of ServerRoot. By default it is c:/Apache24. It needs to be changed to whatever Apache installation directory you chose — in our example, C:/_a/Apache.

Find the line where ServerName is commented out. Remove the comment character, and optionally change the value to whatever you wish. The default value, www.example.com:80, is as good as any, at least for local usage, because apparently it does not have to be any meaningful value. If you do not set it to at least some value, then when you start Apache in a Windows terminal (a.k.a. command prompt, a.k.a. DOS box), then you will probably get a warning message: "AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using ::1. Set the 'ServerName' directive globally to suppress this message".

Then find the line that defines DocumentRoot, and change it to whatever directory on your machine is high enough in the file structure to encompass all the files you want Apache to serve up, such as HTML files, website root directories, and PHP scripts. In my case, I set it to D:/, since that partition on my computer houses all of those files.

Also in httpd.conf is the line <Directory "c:/Apache24/htdocs">. Change its directory to whatever you set DocumentRoot to. Change its directives to be:

AllowOverride all
Require all granted
Options indexes

Save your httpd.conf editing changes.

Starting and Verifying Apache

To confirm that Apache works, open a Windows terminal, go to the bin subdirectory, and enter the command httpd (a cryptic initialism derived from Hypertext Transfer Protocol daemon). Your firewall — in our example, Windows' built-in firewall — may complain that Apache is trying to access the network. (You do have a firewall catching outbound connections, right?)

Windows Firewall message
Figure 7. Windows Firewall message

Allow Apache to access the network. For the Windows 7 firewall, this adds an exception entry in the list of allowed programs for the public network, even though it does not appear to be needed for accessing only local pages. Windows 8 already has an exception entry in its list.

Windows Firewall exception
Figure 8. Windows Firewall exception

Open a web browser, and go to the address http://localhost. If it displays the message "It works!" or an "Index of…" listing of directories, then the Apache server is functioning properly. If your browser complains that "this webpage is not available" (in Google Chrome) or it is "unable to connect" (Firefox), then Apache is not running properly. In the latter case, see the "Troubleshooting" section below.

Devoting a Windows terminal to running Apache ties up a terminal unnecessarily. Let's make Apache run automatically as a Windows service: Stop Apache (by typing Ctrl + C). Open a Windows terminal, and do so as an administrator, otherwise you will later get the error message "(OS 5)Access is denied. : AH00369: Failed to open the WinNT service manager, perhaps you forgot to log in as Administrator?". Go to the bin subdirectory, and rerun the command, but this time with the install option: httpd -k install.

Apache service install command
Figure 9. Apache service install command

Incidentally, to get information on all of the available command-line options, use the help option: httpd -h.

Apache command-line options
Figure 10. Apache command-line options

View the status of all the Windows services ("Control Panel" > "Administrative Tools" > "Services"), and see if Apache is installed.

Windows services with Apache not running
Figure 11. Windows services with Apache not running

Try to start Apache manually, by clicking the "Start" link in the middle panel, under the "Apache2.4" label. If the installation process was completed successfully, then you should now see that the Apache2.4 entry has a "Status" value of "Started".

Windows services with Apache running
Figure 12. Windows services with Apache running

That entry should also have a "Startup Type" value of "Automatic", which naturally means that each time that you restart Windows, Apache will try to start automatically — saving you the trouble of having to do it manually each time. To verify that it is working, restart Windows and check the Windows Services dialog box again, where you should find that Apache again has a status of "Started". Then go to your web browser, and verify that the http://localhost URL works exactly as before when you manually started Apache.


At this point, you are finished with the installation and basic configuration of your new web server. If, however, you have encountered problems somewhere in this process, first check the error log file (logs\error.log) to see if anything obvious is going wrong. Also check the online documentation.

If you are able to start Apache from the command line, but not as a Windows service, then your environment may be missing a needed DLL. If your environment requires one of the Visual C++ packages described earlier (in the "Installing Apache" section), then you will see different problems depending upon how you try to start Apache.

If you try to start it in the Windows Services panel, then you may receive an error 1053 dialog, containing the useless message that "The service did not respond to the start or control request in a timely fashion".

Windows services error 1053
Figure 13. Windows services error 1053

Alternatively, if you put a shortcut to the Apache executable in the Startup folder, then on restart you may get the error "The program can't start because MSVCR100.dll is missing from your computer".

In both cases, this suggests that the Visual C++ 2010 Redistributable Package was not correctly installed.

If your web browser outputs an error message "Forbidden You don't have permission to access / on this server", then doublecheck the earlier <Directory> settings.

For more advanced troubleshooting, use your favorite search engine to seek out help that corresponds to the error messages and misbehavior that you are seeing. Do not be astonished if you find the process quite fruitless and frustrating, given how cryptic and incomplete are most of the instructions.

Even though this article contains only basic information, you now should know enough to be able to turn your Windows computer into a local web server.

Copyright © 2013 Michael J. Ross. All rights reserved.
bad bots block