Although I have written a number of articles on installing Apache 2.2, 2.0 and 1.3 on Windows in the past, they were designed for installation on Windows XP and earlier. With Windows Vista now being used by more developers, people are finding that getting Apache to install successfully, let alone work, on Vista is not trivial. This tutorial deals with how you can set up Apache 2.2 on Windows Vista so that it will not only work properly, but is also easy to configure and to update.
This guide only applies to the Apache 2.2.x series, where "x" stands for some number. I have not tested the procedure for any other version of Apache.
This tutorial was specifically written for Vista. If you are installing Apache on an earlier version of Windows, please see one of the following articles instead:
Since Apache is constantly improving its web server, there's a chance that the tricks and workarounds described in this article are no longer necessary by the time you read this article, and that all you need to do is to download and run the Apache installer. As such, I should probably mention that the procedure described below was tested for version 2.2.10 of the server. If you are using a later version, you may want to try to install the server in the normal way, and see if everything works properly. If it doesn't, uninstall it, delete all remnant folders that the uninstaller leaves behind (in the "Program Files" directory), and follow the procedure below.
The first thing you must do before you try to install Apache 2.2 on Vista is to make sure that there are no other programs listening on port 80 of your computer. Very loosely, in layman's language, "Port 80" is just the special interface on the computer that a web server monitors. When a browser tries to connect to a website located on the server, it will by default connect to port 80. When Apache is installed on a computer, it monitors port 80, that is, it "listens on port 80". If something else is already listening on port 80, your installation of Apache will fail.
There are probably many ways to discover if there is any program monitoring port 80. One way is to use the "netstat" program from the command prompt.
To open a command prompt in Vista, click the Windows button (ie, the Start menu, although it's no longer labelled as such), type "cmd" into the empty field, and hit the ENTER key. A black command prompt window will open.
In that window, type "netstat -ao" (without the quotation marks) and hit ENTER. (Note: the "o" in "-ao" is the letter "o".) If your window is too small for you to see all the lines, you can scroll up (with the scroll bar on the right side of the window) to view the entire list.
Look for any line that has "TCP" in the first column (the "Proto" column), a string of characters that end in ":80" in the "Local Address" column (typically "0.0.0.0:80"), and "LISTENING" in the "State" column. If so, it means that you have some program already listening on port 80. To find out which program, note the number in the PID column of that line.
Now hit Ctrl+Shift+ESC on your keyboard. That is, hold down the Ctrl and Shift key on your keyboard, and press the ESC key. The Windows Task Manager should open. Click the "Services" tab in that window. Look for a matching PID to find the name of the service that is listening on that port. That is, scroll down the list until you find a line that has the same PID. Then look at the name of the service on the left.
Hopefully, the name of the service is informative enough for you to track down the program that currently uses that port. If so, start up that program (eg from your Start menu) and look for a way to stop it from listening on port 80 in its Options. Programs that listen to port 80 include the IIS (a web server from Microsoft) and Skype. (You can stop Skype from listening on port 80 from its Advanced Options.)
If you have already tried installing Apache once before, make sure you uninstall it and then go through your "Program Files" folder and delete any remaining Apache files. If you don't, your new installation won't work correctly.
When you've finished with the above, close the command prompt window and the Windows Task Manager. (Just hit the "X" close button on those windows.)
If you haven't got Apache 2.2, download it from the Apache site. Since this guide deals with the 2.2.x series, simply click the "Download" link under the 2.2.x (where "x" is some number) section. You will be brought to the download page. Scroll down and look for one of the "Win32 Binary" links. I used the "Win32 Binary without crypto (no mod_ssl) (MSI Installer)" link for my purposes. Make sure that you get the 2.2.x version (where "x" is some number) and not the 2.0.x (again, where "x" stands for some number) binary, otherwise your installation procedure will not match those given in this guide.
Save the file on your desktop. (Technically speaking, you can save it anywhere you like, but I shall assume that you saved it on your desktop in this tutorial. It's best that you save it on your desktop if you're following this tutorial, otherwise some of the command lines that you will use below won't work correctly.)
Before you run the installer, you will need to open the command prompt window as administrator. To do this, click the Start menu button, the "All Programs" menu item, the "Accessories" folder, and look for the item "Command Prompt". Do NOT click it, or you'll be running the command prompt with normal rights (even if you're logged in as an administrator). Instead, right click "Command Prompt" (click with the right mouse button), and click the "Run as administrator" item in the menu that pops out.
Vista will prompt you with a dialog box entitled "User Account Control". Click the "Continue" button. A command prompt window will open. This command prompt window has the title "Administrator Command Prompt" instead of the normal "Command Prompt" or "c:\Windows\system32\cmd.exe".
(If you do not see the title "Administrator Command Prompt" on your command prompt window, it means you did it wrongly. Close the command prompt window and redo this step, this time following every step of my instructions.)
Type the following line into the window followed by the ENTER key. Include all the quotation marks and the percent sign. (That is, type it literally as given.)
This command switches you to your desktop directory, where you have saved your Apache installer. For example, if your Vista username is "chris", you should now be in the "c:\Users\chris\desktop" directory. Next, you will need to run the Apache installer from this command line. The actual name of the Apache installer file is different depending on the version you downloaded. For example, at the time I wrote this article, the file I downloaded was called "apache_2.2.10-win32-x86-no_ssl.exe". Later versions may, instead, have an ".msi" extension, like "apache_2.2.11-win32-x86-no_ssl.msi", although you may not be able to see any file extension, depending on how you have configured Vista.
Now run the installer by typing the full name of the file (including the extension, especially if it has an ".msi" extension) on the command line and hitting ENTER. If you are too lazy to type the full filename, are a slow typist or simply afraid that you'll give the wrong filename, a shortcut is to type "apache" and hit the TAB key. The command line shell (the Command Prompt) will immediately try to complete the filename for you. If you have many files on your desktop starting with the word "apache", just keep hitting the TAB key until Command Prompt auto-completes the correct filename for you.
When the correct filename appears, hit ENTER to run the installer. The Apache installation wizard will then pop up.
Follow the installer's instructions on setting up the web server (that is, read the information displayed in each dialog box, and click the necessary buttons). For the most part, installing is pretty straightforward. Don't worry, the not-so-straightforward portions are described in detail in the next few paragraphs.
When you come to the "Server Information" window, enter "localhost" (without the quotation marks) in both the "Network Domain" and "Server Name" fields. In the "Administrator's Email Address" field, enter whatever email address you wish. In theory, this information is used by the installer to create a default configuration file for your web server. (In practice, the installer seems to ignore whatever you enter here. But you should still enter what I said earlier, just in case the installer has been fixed in the version you use.) You can easily modify this in your configuration file later if you change your mind.
Leave the default option "for All Users, on Port 80, as a Service" as it is. When you're satisfied with what you've entered, click the "Next" button.
When you're presented with the "Setup Type" screen, leave the default setting of "Typical" and click "Next". You'll be asked for the location to install Apache. Leave it at the default of "c:\Program Files\Apache Software Foundation\Apache 2.2\". I will assume that you've installed to this location in the rest of this article. Click "Next".
When the "Ready to Install the Program" window appears, click the "Install" button. The setup utility will proceed to set up Apache on your machine.
When the installer is done, click the "Finish" button to dismiss it. There should be no error messages or error windows. (If you get any errors, it probably means that you did not rigorously follow my procedure in this guide. To solve it, uninstall everything and start again.)
Do not close the administrator command prompt window that you opened earlier. You'll need it again later.
Once you've finished all the above steps, you should be able to see a new icon in your system tray. This is the Apache Monitor. If you're not sure which icon in your tray is the Apache monitor, move your mouse button over each icon and wait for the tooltip to appear. The Apache Monitor should give a tooltip of "Running all Apache services" after you have successfully installed the program.
Doubleclick the icon to open up the Apache Monitor program. A window, "Apache Service Monitor", will appear. This program allows you to start and stop the Apache web server on your machine. By default, the setup utility starts the Apache web server. If you want to the server to run only when you actually test your website on your computer, you can use the monitor to stop and start it.
At the risk of stating the obvious, clicking the "Stop" button will stop the Apache web server service. The "Start" button starts it. If you make a change to the Apache configuration file (see later in this article), you will need to hit the "Restart" button to reload the Apache service, so that the server will reread the configuration file. When you're through playing with the buttons, click the "OK" button (not the "Exit" button) to return the Monitor to the system tray. If you have accidentally hit the "Exit" button and found that you've killed the Monitor, you can restart it again from your Start menu. (Type "monitor apache servers" in the Start menu search field.)
If a button is disabled, it means that it's not relevant to the current situation. For example, if the Apache web server is already running, the "Start" button will be disabled. You can pretty much ignore the other buttons.
At this point, the Apache web server is fully functional. To make sure that the server is properly set up, start up your web browser, and go to the address "http://localhost/". If you see a simple web page with the words "It works!", it means that the server installation was successful.
Even though Apache may now be properly installed on your system and running smoothly, in its current state, it is not convenient to configure or even copy your website files to it.
The problem is that the current Windows version of Apache 2.2 installer (version 2.2.10 at the time I wrote this article) was not really written with Vista in mind. As such, things that you frequently need to modify, like the configuration file and the web server files, are located in the "c:\Program Files\Apache Software Foundation\Apache 2.2\" folder. In Vista, the "Program Files" folder and its descendants are protected folders that programs can access only if they are run with administrator privileges (like we did earlier when we ran the Command Prompt as administrator).
If we leave things in this state, the only way that you can configure Apache is to run your editor as administrator. And when you need to copy your website's files to your local server, you'll need to do it when running as administrator. All in all, this makes things very troublesome for the web developer.
As such, until the Apache developers update the server to directly support Vista installations, you may want to do the following to make your life easier.
Create a new folder, either on your Desktop or in your Documents folder, called "apache". Actually, it doesn't matter where you create the folder or what you call it. However, for the purpose of this tutorial, I will assume that you created a new empty folder called "apache" on your desktop. That is, if your username is "heng", you will have a new folder called "c:\Users\heng\Desktop\apache".
(To create a folder, right click your desktop and select "New" from the menu that appears, followed by the "Folder" item in the submenu. Rename the "New Folder" to "apache".)
Open the folder by doubleclicking it. It should be empty. Leave the window open.
Click the start menu followed by the "Computer" item in the menu. This will open an Explorer window. Navigate to "c:\Program Files\Apache Software Foundation\Apache 2.2\" in the usual way you go to different folders on your computer. (That is, doubleclick the C: drive, then the "Program Files" folder, then the "Apache Software Foundation" folder, and finally the "Apache 2.2" folder).
Look for the folder "conf". Right click the folder and select "Copy" from the menu that appears. Switch to the "apache" window that you opened in the previous step. Right click in the empty space in that window and select "Paste". Do the same for the "htdocs" folders as well. Do NOT drag and drop them. Copy and paste the folders or you will end up with folders and files having the wrong permissions.
By the end of this step, you should have two copies of the "conf" and "htdocs" folders: one in your "Apache 2.2" Program Files folder, and one in your Desktop "apache" folder.
Open the Apache Monitor by doubleclicking on its system tray icon. Click the "Stop" button to stop the service. When the service has stopped, you will see a message in the lower window "The Apache2.2 service has stopped". Click the "OK" button.
Now switch back to the first window, the one pointing to "c:\Program Files\Apache Software Foundation\Apache 2.2\". Right click the "conf" folder and click "Delete" from the menu that appears. You will be asked to confirm in triplicate (I'm not kidding). That is, a dialog box will appear asking if you are sure that you want to move the folder to the Recycle Bin. Click "Yes" to the prompt that appears. Another dialog box, with the title "Destination Folder Access Denied" will open, asking you to confirm the operation. Click "Continue". Yet another window, the "User Account Control" will appear, again asking for your permission to continue. Click "Continue" again.
Repeat the procedure with the "htdocs" folder.
Switch to the Administrator Command Prompt that you opened earlier.
Type the following line into the "Administrator Command Prompt" window and hit the ENTER key.
Be sure to type the opening and closing quotation marks (yes, the quotes are needed). The command will bring you into the Apache folder. To make sure you're in the right folder, type "dir" (without the quotes) followed by the ENTER key. You should see the same files and folders that you saw earlier in the Explorer window, albeit arranged in a different order.
Type the following command, followed by the ENTER key. Notice that the command line includes characters like the quotation marks and the percent sign. All the characters are required.
The shell (command prompt) will print reassuring words to the effect that a symbolic link has been created and where the link points to.
If you make a mistake creating the symbolic link, so that it points to the wrong location, delete it by typing "rd conf" followed by the ENTER key. Then try again. Note that my above command line assumes that you have created a folder called "apache" on your desktop, as I mentioned earlier.
Finally, create a symbolic link for the htdocs directory.
To make sure that all is well, doubleclick the Apache Monitor icon again, and start the web server service. (That is, click the "Start" button in the Monitor window.) Then open your web browser and surf to "http://localhost/". The "It Works!" web page should appear. If "It Works" does not appear, and you get a directory listing of some other directory, it means that your "htdocs" link is pointing to the wrong location. Delete the existing link with "rd htdocs" in the Administrator Command Prompt and try again.
The "htdocs" subfolder that we created in your desktop "apache" folder is where all your web pages live. Since the folder directly resides on your computer, you don't have to do anything special to "publish" your website files. That is, you don't have to upload your pages using FTP or anything like that. (You can't anyway, unless you set up an FTP server in addition to your web server.) All you need to do is to copy your files to the "htdocs" folder and it will be displayed by Apache when there is a request for them.
Remember how I mentioned earlier that if you change your mind about the email address you enter into the Apache setup utility or the domain name, you can change it later? For those who actually need to change these settings, you will have to modify the Apache configuration file, "httpd.conf". This file, if you have followed my procedure above, lives in the "conf" subfolder in your desktop "apache" folder.
To edit it, either load it in Notepad directly, or invoke the Start menu, type "apache" into the "Start Search" box, and select the "Edit the Apache httpd.conf Configuration File" item that appears. This will invoke Notepad to load httpd.conf. Note that you should always use an ASCII or programmer's text editor to edit this file. Notepad is fine. But never use a word processor or office program. For example, any program that allows you to underline text, make things bold or italicize words should NOT be used.
To change the server name, look for the following line and replace "localhost" with the domain you want.
If the "ServerName" entry is preceded by a hash ("#") sign, and there are no other "ServerName" entries in the file, remove the hash before you modify the line.
To change the Administrator's email address, look for a line like the following (that is, starting with "ServerAdmin") and replace the email portion with whatever you want:
Once you're done with your changes, save the file by selecting the "Save" item from the "File" menu. Then invoke the Apache monitor and click the "Restart" button to restart the server.
In general, if your purpose for setting up Apache is to test your site on your own machine before you upload it "live" onto a real web host, you don't have to change anything. For most people, the default settings are fine for such purposes.
(As a side note, if you're thinking of buying your own domain name and attaching it to your web server, please note that your server, as currently set up, is not suitable for live deployment on the Internet. Live deployment requires additional security measures, not dealt with here. You will also need to have your domain point to your machine's real IP address in a name server.)
If you want the web server to handle Server Side Includes (SSI), search for the text "server-side includes" in the configuration file. (If you skipped the previous item, and thus don't know how to load the Apache configuration file, please return to that section to find out how it is done.)
The text you found should be in a section of lines all preceded by the hash ("#") sign. Any line that has a hash mark at the start is regarded as a comment by the Apache web server. Comments are ignored by the server, and are meant as explanatory text for human beings to read. They don't do anything except give information to human readers.
Add the following lines immediately after that block of comments. The lines should be added ABOVE the closing
AddType text/html .shtml AddOutputFilter INCLUDES .shtml
If you look carefully at the commented text, you will notice that the configuration settings I provided above are mirrored exactly in the last two lines of the commented block. Instead of adding my lines, you can also uncomment those two lines in your file by removing the initial hash ("#") prefix before each line.
When you do this, your Apache server will now be able to recognize files ending with the ".shtml" extension, and parse them for SSI directives.
For those who want "index.shtml" to be your default start page for your directories, ie, if you want Apache to load "index.shtml" when you type "http://localhost" or "http://localhost/directory/", you will need to search for the following line in your "httpd.conf" file:
Replace that line with:
This setting causes Apache to first look for an "index.shtml" file in the directory and use that as the default page for that directory. If this file cannot be found, it will look for the next file specified. That is, Apache goes through the list of filenames in the order given.
When you're through with the configuration, save the file by clicking "Save" from the "File" menu. Again, you will have to invoke the Apache Monitor and click the "Restart" button to restart the server. This is needed because Apache only checks the configuration file once, when it loads. Any time you change the configuration file, you need to click the "Restart" button to make sure that Apache recognizes your new configuration.
Out of the box, Apache does not contain support for PHP or Perl. If you want your server to support PHP scripts, please see the article How to Install and Configure PHP 5 to Run with Apache on Windows.
I also have an older article How to Add Perl CGI Script Support to Your Apache Server on Windows that deals with adding Perl to Apache. That article was written for Apache 1.x, and is thus probably not very relevant to the 2.x series. I'll eventually get round to updating the article for Apache 2 on Vista, but in the meantime, if you're really stuck, it may provide some tips on what to look for when installing Perl.
(Note: If you want to be notified when these articles are updated or when new articles are published, please subscribe to thesitewizard.com's news feed. Instructions on how to do this can be found in my FAQ How to Subscribe to or Read News Feeds. Subscription is free, of course.)
Congratulations! You have now not only installed Apache 2.2.x successfully on Windows Vista, you've also configured it and made the overall use of Apache very much easier so that each time you modify its settings or update your website, you don't have to face multiple UAC prompts from Vista. And you didn't even have to permanently disable UAC (which, in spite of its detractors, has its uses) to accomplish it.
This article can be found at http://www.thesitewizard.com/apache/install-apache-on-vista.shtml
Do you find this article useful? You can learn of new articles and scripts that are published on thesitewizard.com by subscribing to the RSS feed. Simply point your RSS feed reader or a browser that supports RSS feeds at http://www.thesitewizard.com/thesitewizard.xml. You can read more about how to subscribe to RSS site feeds from my RSS FAQ.
This article is copyrighted. Please do not reproduce this article in whole or part, in any form, without obtaining my written permission.
It will appear on your page as: