Install the Apache Web Server on Windows

How to Install the Apache Web Server on Windows

Learn how to install the Apache Web Server on Windows (32bit/64bit) to allow you to test websites on your local computer.

There are various packages available for installing a WAMP (Windows, Apache, MySQL, and PHP) environment via an installation Wizard, however, I recommend that you install the packages manually. This is because you will have control over which versions of software you install, and will gain a good understanding of how to configure, and manage your setup.
If an automatically installed server environment breaks, it can be very time consuming figuring out how to fix it. There are numerous forum posts online where people are spending days to resolve issues related to WAMP servers failing to work properly.

Apache Lounge provides Windows builds of the source code available fromApache Software Foundation (ASF) using the latest Visual Studio C++ compiler environment.

The Windows installer package available from ASF is easier to use, but it installs Apache in the Windows Programs area (requiring Administrator Mode when editing the configuration files), and may use an older compiler such as VC6. Also, it locates all of your websites in the Windows programs area, which is a bad idea.

Download Apache Web Server - choose the latest version for your version of Windows (32 bit or 64 bit).

While you are there, you might want to download the FastCGI module extension too, since later we will use this to enable PHP.

After downloading the zip file, you are advised to verify the integrity of the file, to ensure that it has not been tampered with. But of course, hardly any Windows user will go through the hassle of doing this. Anyway, here is the procedure:

Choose one of the checksums from the published list in the download area e.g. the SHA1 hash. Then run the downloaded zip file through a utility such as Microsoft File Checksum Integrity Verifier (this works in Windows 7, from the command window) to generate a SHA1 hash value. Then compare this to the expected value. If they are the same, then the file is verified as ok (assuming that your Checksum Integrity Verifier was not compromized).

After downloading, the zip file contains a folder called Apache24. Move (unzip) the Apache24 folder to C:\\ (now the webserver files are located at: C:\\Apache24).

The main configuration file for the server is: C:\\Apache24\\conf\\httpd.conf

Using a text editor, you need to edit the entry for the Server Name to give it a name, remove the comment from the line:
ServerName www.example.com:80

This will prevent a problem with starting the server when you do the next step.
Open a Command line box in Administrator mode. To do this: enter cmd into the Start Menu search box, and do: Crtl + Shift + Enter. Then confirm that you want to make changes to your computer.

Now navigate to the bin folder of Apache.
>cd \\Apache24\\bin\\

Now install Apache as a service:
>httpd.exe -k install

Note: to simply run the server, enter: >httpd.exe Tip: this is a good way to view error messages should the server fail to start.
Now, to easily control the server (start, stop, and restart it), you can make use of: ApacheMonitor.exe

To start the Apache Monitor, enter:
>ApacheMonitor.exe

Now it will be available in the Windows task bar, showing the Apache feather, with a green arrow (server running), or a red arrow (server stopped). Clicking on this icon gives you access to the server control menu.



You need to restart the server anytime you make changes to the configuration settings. Or if you want to run another server such as IIS, you need to turn it off.
Create a shortcut for ApacheMonitor.exe and place the shortcut in your Startup folder. So Apache should start up automatically when you next boot up your computer.
Now, if you enter http://localhost/ into a web browser, it should display "It Works!".

Trouble-shooting Apache

If Apache doesn't work, you can find an error log file in C:\\Apache24\\logs\\ which you can view with a text editor.
If Apache won't start, it's likely that there is another application or service using port 80 of the computer. This port is used for listening for web requests.
Applications such as Skype, IIS, or services such as "Web Deployment Agent Service", or "SQL Server Reporting Services" may be causing the conflict.
You can turn services off via: Control Panel -> System and Security -> Administrative Tools -> Services

Customizing the Apache Server Configuration

Now you may customize the server configuration.
You may locate your websites somewhere other than the default area (C:\\Apache24\\htdocs\\). To do so, create a directory such as C:\\htdocs Then edit the Apache server configuration file to point the server at this directory.
To avoid "access denied" messages, comment out: Require all denied
For the first Directory block, I ended up with this code:
<Directory />
AllowOverride none
# Require all denied
Options FollowSymLinks
Order deny,allow
</Directory>
Deny from all
Change the document root to:

DocumentRoot "C:/htdocs" 
<Directory "C:/htdocs">

Under:
#
# Dynamic Shared Object (DSO) Support
#
Un-comment any extra modules that you may need such as:
LoadModule rewrite_module modules/mod_rewrite.so
To allow for URL re-writing (a useful feature), you need to add some directives as follows:
Look for the line: # This should be changed to whatever you set DocumentRoot to.
Then edit the following code to read like this:

<Directory "C:/htdocs">
#
# Possible values for the Options directive are "None", "All",
# or any combination of:
# Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews
# # Note that "MultiViews" must be named *explicitly* --- "Options All"
# The Options directive is both complicated and important. Please see
# doesn't give it to you. # # http://httpd.apache.org/docs/2.2/mod/core.html#options
# AllowOverride controls what directives may be placed in .htaccess files.
# for more information. # Options Indexes FollowSymLinks #
AllowOverride All
# It can be "All", "None", or any combination of the keywords: #Options FileInfo AuthConfig Limit # #
</Directory>
# Controls who can get stuff from this server. # Order allow,deny Allow from all
After this section, add index.php to the list of index files:
#
# DirectoryIndex: sets the file that Apache will serve if a directory
# is requested. # <IfModule dir_module>
</IfModule>
DirectoryIndex index.php index.html
After this section, add "Satisfy All" to:
#
# The following lines prevent .htaccess and .htpasswd files from being
# viewed by Web clients. # <FilesMatch "^\.ht">
</FilesMatch>
Order allow,deny Deny from all
Satisfy All
Allow the virtual hosts file to be used:

# Virtual hosts
Include conf/extra/httpd-vhosts.conf
After making these changes, save the file, and restart the server.

No comments:

Post a Comment