How to install Apache on Windows and Configure it to Run SSI & CGIs for more than one Virtual Website

Snappy page title, huh?

Having recently migrated to a new laptop and having just gone through this tricky process once again, I decided to write up these notes mostly for myself, and to put them online so I will be able to find them if ever I need them again (which I probably will)... so they are tailored to how I like to set up Apache...

...for example, I like to partition my hard drive to separate the Windows System from Programs and my Files, so instead of using the default location (usually under C:\Program Files\) I will be installing Apache on drive D: and keeping the local copy of my website(s) on drive E: ...

For a more generic guide with longer explanations for each step see the article on www.thesitewizard.com: How to Install and Configure Apache 2 on Windows (the guide I referred to myself when I needed help)

INSTALLATION

1. Download Apache 2 & Run the Installer

2. At the "Server Information" page:

3. At Setup Type, select "Typical"

4. At Destination Folder

 

CONFIGURATION

1. In Control Panel -> Administrative Tools -> Services -> "Apache2"

2. Use a basic text editor (e.g. notepad) to open the file "httpd.conf" in the folder "%Apache2%\conf\" (where %Apache2% is the path you set in step 4 above i.e. D:\Apache2.2\conf\httpd.conf)

3. Search for the text "server-side includes" and delete the hashes at the beginning of these following lines:

    #AddType text/html .shtml
    #AddOutputFilter INCLUDES .shtml

so that they read:

    AddType text/html .shtml
    AddOutputFilter INCLUDES .shtml 

4. Search for "DocumentRoot" and edit the following line:

    DocumentRoot "%Apache2%/htdocs"

to point to the path where you want to save your website(s), e.g:

    DocumentRoot "E:/home"

5. and just below that you will find the line:

    <Directory />

do not edit it, but look below that you will find the same line again. Edit:

    <Directory />

to read:

    <Directory "E:/home">

6. a few lines further down you should find:

    Options Indexes FollowSymLinks

edit it to read:

    Options Indexes FollowSymLinks Includes ExecCGI

7. Search for the following line:

    #AddHandler cgi-script .cgi

and delete the hash so it reads:

    AddHandler cgi-script .cgi

8. a few lines below that you will find:

    #AddType text/html .shtml
    #AddOutputFilter INCLUDES .shtml

delete the hashes so these lines read:

    AddType text/html .shtml
    AddOutputFilter INCLUDES .shtml

9. Scroll to the end of the file and add these lines, one group tailored for each of your local websites (note each must have a unique URL 127.0.0.xxx):

    <NameVirtualHost 127.0.0.1
    <VirtualHost 127.0.0.1>
    DocumentRoot "E:/home/georgedillon.com"
    ServerName georgedillon.com
    ErrorLog "E:/home/georgedillon.com/logs/error.log"
    CustomLog "E:/home/georgedillon.com/logs/localaccess.log" common
    ScriptAlias /cgi-bin/ "E:/home/georgedillon.com/cgi-bin/"
    </VirtualHost>
    <Directory "E:/home/georgedillon.com/cgi-bin">
    Options +ExecCGI
    </Directory>
    <NameVirtualHost 127.0.0.2
    <VirtualHost 127.0.0.2>
    DocumentRoot "E:/home/stevenberkoff.com"
    ServerName stevenberkoff.com
    ErrorLog "E:/home/stevenberkoff.com/logs/error.log"
    CustomLog "E:/home/stevenberkoff.com/logs/localaccess.log" common
    ScriptAlias /cgi-bin/ "E:/home/stevenberkoff.com/cgi-bin/"
    </VirtualHost>
    <Directory "E:/home/stevenberkoff.com/cgi-bin">
    Options +ExecCGI
    </Directory>

IMPORTANT: The 2 log files ErrorLog and CustomLog MUST EXIST for EVERY website listed here, or Apache will crash when it starts

10. Save the file and close the text editor

FINALLY:
11. To get your cgis to run (and avoid the dreaded "can't spawn child process error message"), you need to define your shebang line as

     #!perl

You may need to alter this before uploading to a unix server to the more usual:

     #!/usr/bin/perl

TESTING:

1. Right click on the Apache Service Monitor icon in the Taskbar and click 'Start'
2. If you have followed the steps above correctly, in the upper (Service Status) window the icon next to Apache 2.2 will turn green and in the lower window you will see the message "The Apache2.2 service has started."
3. Open a browser and type in the address bar http://127.0.0.1/ and your website will appear
4. IF Apache does not start correctly, then check that you have followed all the steps above accurately, that all paths are correct and that the log files exist for each virtual host


  Back to top    Back to top
{Printed from http://www.georgedillon.com/web/apache_configuration.shtml on Tue, 21 Nov, 2017 @ 23:18:44}