Installing Apache on Windows
Even though it is possible to do Web development and testing on a remote server, it is better to fully develop a new Web site on a local Web server, and then upload everything when it is finished, for many reasons:
1) Keeping the unfinished site off the Internet is safer, because as you begin developing the site, you probably have not put in all of your code for neutralizing any potential attacks against your site, including cross-site scripting (XSS) vulnerabilities.
2) You may already have sensitive data in the database for testing.
3) When you want to make future modifications to a site that is already live (i.e., on the Internet and available to the public), it is better to make changes (and mistakes!) on your PC, where they will be seen only by you. You don’t want to risk disrupting the functioning of your production server.
4) If you prefer to work mobile, you can modify your site even without being connected to the Internet.
5) You can see those modifications without wasting time FTP-ing files up to the remote server.
Programmers new to Web development have likely heard of Web servers, but may not be completely sure as to what they are. The term "Web server" has two, albeit related, meanings: It refers to any computer program that receives HTTP requests from client programs — usually Web browsers running on remote computers — and responds to those requests by serving up data — usually Web pages and their elements. The term also refers to the computer running such a server program.
The two most commonly used Web servers in the world are Apache, offered by The Apache Software Foundation, and Internet Information Services (IIS), offered by Microsoft. Because this tutorial assumes that you are using Microsoft Windows, you have the option to use either Web server. I heartily recommend Apache, and that is what we will focus on here. IIS is built into Windows, and some developers may consider that reason enough to eschew IIS.
Regardless, Apache has some appreciable advantages: As the most popular choice, there are greater chances of finding information on it, and assistance from other programmers. Apache is free and open source, hence the code has received much greater scrutiny than proprietary alternatives, and thus probably has fewer bugs and, more importantly, security holes. Also, Apache runs on operating systems other than Windows, including Linux and Mac OS. If you are using Mac OS X, then Apache is already installed, but needs to be activated (System Preferences > Sharing > Personal Web Sharing).
For this tutorial, we will be using the most recent stable version of Apache, which as of this writing is version 2.2.8. In addition, we will be using Windows XP Service Pack 2. If you are using a different version of Windows, it is quite possible that the menu options that you will need to follow will be slightly different, and the dialog boxes and other screens will appear different from the figures in this tutorial. However, the equivalents for your own version of Windows should be easy to discern.
Apache Already Installed?
Before you start installing a brand new instance of Apache on your
development machine, you should first determine whether or not you
already have an earlier version of Apache installed, and if so, what to
do about it. First, check what Windows services are installed and
possibly running on your PC. Go to Start > Settings > Control
Panel > Administrative Tools > Services, then click the Standard
The third entry in the list shows that Apache 1.3.33 is currently
running, with the status of "Started". You should stop the service
manually, because uninstalling Apache is not sufficient to stop the
service — at least for version 1.3.x. To stop the Apache service,
right-click on the line, and in the context menu that pops up, choose
"Stop". A dialog box will show the progress of Windows shutting down
If Apache is not listed in the Windows services, it may nonetheless
be installed on your PC, but configured to only be run manually, and
not registered as a service. Either way, you should next try to find
any Apache installation, by looking in all directories where you have
installed applications in the past. "C: Program Files" is the default
installation directory. It is possible that you have more than one
version of Apache installed, probably in separate directories whose
names contain the version numbers.
In this example, we will assume that only a single instance of
Apache, version 1.3.3, has previously been installed. To uninstall it,
go to Start > Settings > Control Panel > Add or Remove
Programs. Click on the Apache entry in the list, and then click the
Even after uninstalling Apache, there may be many files left behind,
in three directories: conf, htdocs, and logs. To do a clean install,
delete these leftover files and directories. But first save any
configuration files that might be valuable to you in the future, such
as confhttpd.conf and htdocsphpMyAdminconfig.inc.php.
Reboot your PC, and check the Windows services again. Usually
uninstalling an application is sufficient to remove it from the
services list. But if Apache is still listed, you can remove it by
editing your Windows Registry. On the command line, run either
"Regedit" or "regedt32". Make a backup of your Registry. Find and
delete the Registry key
again, to fully update the services list.
To get the latest version of Apache (2.2.8 as of this writing), go to the Apache download page.
In the "Apache HTTP Server 2.2.8" section of the page, click on the
link for "Win32 Binary without crypto", which begins downloading the
To the right of the filename are links for obtaining the PGP and MD5
signatures, if you want to confirm the integrity of the file after you
have downloaded it to your PC. The other two Win32 links would be used
if you wanted to download the Apache source code, or to use OpenSSL.
Those topics are not covered in this tutorial.
Find the installation file, apache_2.2.8-win32-x86-no_ssl.msi,
wherever you saved it on your PC. Open the file, which starts the
installation process, using the Windows MSI Installer.
At the welcome dialog box, click the "Next" button.
At the license dialog box, check the radio button to indicate that you accept the license, and click the "Next" button.
The "Read This First" dialog box contains information that may be of
interest to new users, but does not need to be read for the
installation. Click the "Next" button.
In the server information dialog box, Apache has set the initial
domain name ("Network Domain") to "domain_not_set.invalid", as a clear
indication to you that the value needs to be replaced with something
valid. For the local Web server that you are setting up, the correct
value is "localhost". The "Server Name" value can be set to any string.
The administration e-mail address is typically set to "root@localhost".
It is recommended that you install Apache for all Windows users, on
port 80, as a service.
Once you have confirmed that all three new values you typed in are correct, click the "Next" button.
The Apache installation will contain components that are optional,
such as the documentation and the taskbar icon. For most users, the
typical setup will be fine. But if you wish to save some disk space by
excluding the documentation from the installation, or do not want
another icon in your Windows taskbar, choose the "Custom" setup option,
which we will do here.
By default, Apache will be installed in C:Program FilesApache
Software FoundationApache2.2. Either setup option allows you to
change the destination folder. But if the install wizard detects a
previous Apache instance, it will not display the destination folder,
nor the button to change it. In that case, click the "Next" button and
on the resultant dialog box click the "Previous" button, returning you
to the "Custom Setup" dialog box. You should then see the destination
folder and "Change" button. After you have made all of your choices,
click the "Next" button.
You are now ready to install Apache’s files. Click the "Install" button.
The installation process contains many steps, and you will see
several DOS boxes pop up and then disappear, as Apache performs various
operations on individual command lines. When the installation wizard
has completed, it will display a final dialog box.
Click the "Finish" button. You are now ready to verify that the installation was successful.
In a Web browser, go to the address "http://localhost". You will
recognize localhost as the server name specified earlier. This URL may
look strange, but it is valid. If the installation was successful, the
Web page displayed simply reads "It works!"
If your results differ, first check for any errors. All of the
errors and warnings detected by Apache are recorded in its log file,
If you are interested in verifying some of the additional changes
made to your system, you can start by examining the top-level Apache
directories and files, in your favorite file browser. The modification
and creation dates that you will see will differ from those shown in
the screenshot below.
The installation process should have added a new menu group to your Start menu.
Apache’s configuration files are stored in its "conf" directory, and httpd.conf is the primary configuration file. This is where you will make most if not all of your customizations to Apache’s configuration. For instance, if you plan on using RewriteRule commands in any.htaccess files, then in your httpd.conf file, in the LoadModule section, uncomment the command "LoadModule rewrite_module modules/mod_rewrite.so".
To activate any configuration change, restart Apache. Then check the aforesaid log file for any errors or warnings.
Directory access is initially set to be extremely restrictive. Consequently, if you use the default configuration and try to have Apache serve a local Web page outside of its default DocumentRoot (C:Program FilesApachehtdocs), then it will give you an error message that you do not have permission to access the file. To resolve this, find the "" section in httpd.conf, and change "AllowOverride None" to "AllowOverride All", and "Deny from all" to "Allow from all".
I recommend that you use comments to document, for your future reference, any changes that you make within httpd.conf. Also, make and verify each configuration change individually, thereby making it much easier to determine which change may be causing a problem. Lastly, new entries can usually be grouped at the bottom of the file. Continuing the example of using the HTTP rewrite module, to specify the rewrite log file and log level, you could add the following two commands at the bottom of httpd.conf:
If you use Firefox as your Web browser, then you may notice that every time you start Firefox, Apache reports an error, in triplicate, that it cannot find htdocs/favicon.ico. To resolve this problem, if you chose to install the Apache manual, then simply copy the file manualimagesfavicon.ico into the htdocs directory. Or simply create an empty file htdocs/favicon.ico (the command "echo. > favicon.ico" will suffice).
If you need further information on the Apache Web server, there are several resources available. The version 2.2 documentation is online. Helpful Web sites include Apache Lounge and ONLamp.com’s Apache DevCenter.
To post questions to other programmers, you can subscribe to the official mailing list.
O’Reilly Media currently publishes eight books dedicated to Apache.
Once you have Apache installed and configured on your local development PC, it will undoubtedly become an essential part of your Web programming environment.