Installation and setup of Apache web server in MS Windows operating system

This is a manual on how to download and install an Apache on your personal computer for personal use. It is NOT optimized for security (!!!) nor effectivness; only to have a working web server as easy as possible.

Later it is specified how to use Apache in combination with database system MySQL and programming languages PHP or Perl. You can use Apache also without these programs, or with other programs.

Downloading installers

On the Apache server homepage (httpd.apache.org) in the left menu click Download from a mirror, on the next page choose best available version, click on Other files, go to directory binaries/win32 and download a file with name apache_<version>-win32-x86-no_ssl.msi.

On the MySQL databse homepage (www.mysql.com) in the top menu click Developer Zone, in the right menu Downloads and Documentation click on the first link at MySQL 5.0 Database Server - Community Edition, select the option Windows Essentials (x86) and skip the form.

On the PHP language homepage (www.php.net) click in the top menu on downloads, find Windows Binaries and click on PHP <version> installer.

On the Perl language homepage (www.activestate.com) on the right menu at Downloads click on ActivePerl Free Distribution, skip the form, find Windows and click on MSI.

Run the downloaded installers; first Apache, then the remaining ones in any order.

Setting up Apache web server

Web server has the web pages stored in some local directory, and after typing an address in the web browser, these pages are returned. By default server uses directory C:\Program Files\Apache Group\Apache2\htdocs; but going to such directory is a bit clumsy, so I recommend to create some directory for example C:\www and use that instead.

Apache settings are in file C:\Program Files\Apache Group\Apache2\conf\httpd.conf. Lines beginning with # are comments; when you have a lot of time, read them. If you change something, it is wise to keep the original setting commented, so you can return the original values in the case of troubles.. (Keeping a copy of the original file may be wise too.)

Find the line:

Listen 80

This is the number of port where the server is listening, that is, receiving requests for web pages. The default value is 80; keep it as it is. However, if you have multiple web servers on the same computer, each of them must listen on a different port. So if some other server is already using port 80, set Apache a different value; for example 81 or 8080.

DocumentRoot "C:/Program Files/Apache Group/Apache2/htdocs"

This is a directory where you will create web pages. You can change it for example to:

DocumentRoot "C:/www"

Now find the place where begins the list of properties of that directory:

<Directory "C:/Program Files/Apache Group/Apache2/htdocs">

According to the value of DocumentRoot change it to:

<Directory "C:/www">

Save the configuration file (we will continue to using it later), and start or restart the Apache server. In directory C:\www create a test file index.html with the following content:

<h1>My home intranet</h1>

Start the web server and type an address:

http://localhost/

If the Apache server is listening on some other than standard port (80), use also the port number:

http://localhost:81/

If everything is correct, you should see a page with heading My home intranet.

Using the PHP programming language in Apache server

Again, opent he configuration file C:\Program Files\Apache Group\Apache2\conf\httpd.conf and find the first appearance of the word ScriptAlias. Somewhere nearby add the line:

ScriptAlias /php/ C:/PHP/

Next, find AddType and add line:

AddType application/x-httpd-php .php

Finally, find the section with Action and add:

Action application/x-httpd-php /php/php-cgi.exe

These lines suppose that your PHP programming language interpreter is installed in a directory C:\PHP and it contains a program php-cgi.exe. If the directory or program have different names, you need to modify those lines.

Restart Apache, and in directory C:\www create a test file test.php with content:

<? echo 2+2; ?>

In the web browser, enter the address:

http://localhost/test.php

If everything is OK, you should see a number 4 displayed.

Using the Perl programming language in Apache server

Open the configuration file C:\Program Files\Apache Group\Apache2\conf\httpd.conf and find a description of <Directory "C:/www">. There is the following line:

Options Indexes FollowSymLinks

Add an option ExecCGI, so that the line will look like this:

Options Indexes FollowSymLinks ExecCGI

Now find a part of configuration file where is AddHandler and add there:

AddHandler cgi-script .cgi
AddHandler cgi-script .pl

Restart Apache, and in directory C:\www create a test file test.pl with content:

#!C:\Perl\bin\perl.exe
print "Content-type: text/html\n";
print "\n";
print "OK";

In the web browser, display the following address:

http://localhost/test.pl

If everything is OK, the OK should be displayed.


Google