Many webmasters choose to install a copy of the Apache web server on their machines so that they can test their PHP and Perl scripts before they upload it to their "live" websites. This allows them to fix any problems on their site before it actually affects their website's visitors. This article deals with how you can set up and configure Apache 2 on your own computer so that you can test your scripts and site.
At present, there are three major versions of Apache available: the 1.3 series, the 2.0 series and the 2.2 series. You should choose the version that matches the one used by your web host. If you are using Apache 1.3, you should probably check out my other tutorial, How to Install Apache 1.x on Windows at http://www.thesitewizard.com/archive/apache.shtml
If you're using Windows Vista, please see the How to Install Apache 2.2 on Windows Vista tutorial instead. The later versions of Windows require a different installation procedure.
This installation guide is meant for people who want to install Apache for private offline use, such as to test your own scripts or website on your own machine. It is not intended for you to set up a "live" website that is connected to the Internet. The instructions here do not take into account things like security or your real domain names and the like, which you will need to configure for if your server is going to be exposed to the Internet.
Firstly, download a copy of Apache 2. Since we are talking about Apache 2 here, be sure to scroll down the page to the appropriate section. Select the "Other files" link in that section to get a complete listing of the available Apache 2 versions. In the new page that appears, click the "binaries" folder followed by the "win32" folder. A list of files with different version numbers will be listed.
If you want the Apache 2.0 series, and the current version of the Apache 2.0 series is, say, 2.0.61, look for the file named "apache-2.0.61-win32-x86-no_ssl.msi". Likewise if you want the Apache 2.2 series, and the current version is, say, 2.2.6, go for the file named "apache-2.2.6-win32-x86-no_ssl.msi".
Click it and save the file to your hard disk. Remember where you saved it so that you can run it later.
When you have finished downloading the file, double-click it to run the Apache installer. Follow the instructions to install Apache.
When you arrive at the "Server Information" dialog box, enter "localhost" (without the quotes) for the Network Domain as well as for the Server Name and whatever email address you wish for the "Administrator's Email Address" field. The installer uses the information you enter to create a default Apache configuration file for you. You can always go back and manually change these values in your configuration file if you change your mind later. Leave the default setting of "for All Users, on Port 80, as a Service" as it is. Click "Next" when you're done.
When asked about the Setup Type, select "Typical" and click "Next".
Allow the installer to install to the default folder in the next screen. Note that this tutorial will assume that you are using the default folder of "c:\Program Files\Apache Group\" here. Click "Next".
Finally click the "Install" button to allow the installer to set up Apache. When it is done, click the "Finish" button.
The Apache installer automatically starts the Apache service when it finishes the installation. If you ever wish to stop the Apache 2 service and only start it manually when you need to use it for testing, go to Control Panel -> Administrative Tools -> Services, look for the "Apache2" service and double-click it. From here you can stop the service and change the startup type to "Manual". The Apache service will then terminate and only start when you return to this control panel applet to manually start it. This is useful if, like me, you're only using the server to test your scripts, and don't want the server running all the time.
If you want to change the server name that you entered when you set up Apache, use the Start menu to open the Apache configuration file: you can find the appropriate item at Start -> Programs -> Apache HTTP Server -> Configure Apache Server -> Edit the Apache httpd.conf Configuration File.
A Notepad window will open with your Apache configuration file loaded. If you ever need to load your configuration file with another ASCII editor, it can be found at "C:\Program Files\Apache Group\Apache2\conf\httpd.conf" for Apache 2.0 and "C:/Program Files/Apache Software Foundation/Apache2.2" for Apache 2.2.
Search for the following text and replace the "localhost" with the name you want.
Likewise if you want to change the Administrator's Email Address that you entered earlier, look for a line like the following:
The exact email address displayed will be different, depending on what you entered during the setup process earlier.
In general, if you are just setting up Apache for private offline testing, you can basically leave these settings as they are.
If you want the web server to parse Server Side Includes (SSI directives), search for the text "server-side includes" in the file. Add the following lines just after the block of text containing those words:
Alternatively, you can uncomment the example text given in the configuration file by removing the hash prefix ("#") before each line.
Apache will now handle the SSI directives that occur in files with names ending in ".shtml".
If you want "index.shtml" to be your default start page for your directories, ie, if you want Apache to load "index.shtml" when you type "localhost" or "localhost/directory/", you will need to search for a line in your "httpd.conf" that begins with "DirectoryIndex" and add index.shtml to the list of files there. For example, modify it as follows:
Adding it before index.html means that Apache will give preference to index.shtml if both are present.
When you are satisfied with your changes, save the file - just use the "Save" item from the "File" menu or type Ctrl+S. After you make a configuration change, you need to restart Apache. To do this, go to the Start Menu and click the "Restart" item in the "Control Apache" folder, that is, select Start -> Programs -> Apache HTTP Server -> Control Apache Server -> Restart.
To test if your server is installed and configured properly, open up a browser and type "localhost" in the location bar of your browser. You should be able to see the default Apache test page.
By default, your pages should be placed in the "C:\Program Files\Apache Group\Apache2\htdocs" folder for Apache 2.0 and the "C:\Program Files\Apache Software Foundation\Apache2.2\htdocs" folder for Apache 2.2. When your site is ready, simply delete the existing files in the folder and replace them with those you want to test.
The next thing to do is to learn how you can install PHP to work with your Apache web server. You can find the tutorial for this at http://www.thesitewizard.com/php/install-php-5-apache-windows.shtml
This article can be found at http://www.thesitewizard.com/apache/install-apache-2-windows.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: