How to use Apache as a Web Host on your Windows PC
Without a doubt, the most robust and widely used hosting software is
Apache. Apache is open source software
and is free to use. It is not
necessarily the easiest software to set up, but has proved itself over years as
the best.
Apache is used on many different platforms and is highly scalable. It can be used on Mac’s, Windows, Linux, other
Unix variants, or just about any platform. In fact, you can download the source and
compile it any new or custom platforms if required.
You can download Apache for Windows from here: http://httpd.apache.org/
I would recommend installing the latest version of the software (at
time of writing v2.2.x). Go for the link
that has a Windows installer built in:
Win32 Binary (MSI Installer).
This will set you through a wizard that allows you to choose where to
install it and some basic configuration.
When installing Apache, ensure that you set it up to run as a
service. This will ensure that Apache is
running whenever Windows is loaded. It will
not matter if you haven’t logged in to that computer or are logged in as a
different person – the service will still run.
Please note, when you install Apache as a service, you need to create a
new Windows user account (eg: call it Apache) and grant it permissions for
specific directories.
(from http://httpd.apache.org/docs/2.2/platform/windows.html)
“You may want to create a
separate account for running Apache service(s). Especially, if you have to
access network resources via Apache, this is strongly recommended.
1. Create a normal domain user
account, and be sure to memorize its password.
2. Grant the newly-created user a
privilege of Log on as a service and Act as part of the operating system. On Windows NT 4.0 these
privileges are granted via User Manager for Domains, but on Windows 2000 and XP
you probably want to use Group Policy for propagating these settings. You can
also manually set these via the Local Security Policy
MMC snap-in.
3. Confirm that the created
account is a member of the Users group.
4. Grant the account read and
execute (RX) rights to all document and script folders (htdocs and cgi-bin for example).
5. Grant the account change
(RWXD) rights to the Apache logs directory.
6. Grant the account read and
execute (RX) rights to the Apache.exe binary executable.
It is usually a good practice to
grant the user the Apache service runs as read and execute (RX) access to the
whole Apache2 directory, except the logs subdirectory, where the user
has to have at least change (RWXD) rights.”
If you do not do this, then you can open yourself
up to security issues.
Configuring Apache
Just about everything in Apache is configured in the httpd.conf file.
Handily, Apache installs a link to configure this on the Windows Start
Menu.
Generally speaking, the default configuration are optimal, however you
will need to make some modifications to it to get even the most basic website
going.
Note: You should use forward
slashes in your configuration. Windows
supports back slashes too (/), however Apache can get confused with back
slashes (\) due to its Unix origins.
Note: For the purposes of
illustration I am using one of my websites as an example.
|
This domain name is:
|
www.mikeullrich.com
|
|
It is stored on my Windows host computer on:
|
C:/_Live/mikeullrich.com
|
|
The top level web page is:
|
Default.html
|
The following are the key lines to change in your Apache conf file:
|
ServerAdmin a@b.c
|
Put your email address here.
|
|
ServerName
www.mikeullrich.com:80
|
This is the default name of the web host
|
|
DocumentRoot
"C:/_Live/mikeullrich.com"
|
This is the location where the website is stored on the windows host
computer
|
|
<Directory "
C:/_Live/mikeullrich.com ">
|
As above
|
|
DirectoryIndex
default.html
|
The top level web page on the host.
|
|
ErrorLog
C:/_Live/logs/error.log
|
Assumes that you want your error log in the same directory hierarchy
as the website.
|
|
|
|
If you plan to host more that one domain name from your web host, then
you can configure them using Virtual Hosts. Virtual hosts, in their main form, allow
many domain names to be used with a single IP address.
For every Virtual domain you can set up a different set of parameters,
some of which are similar as mentioned above for the primary site.
Note: For the purposes of
illustration I have a 2nd domain called howtohostawebsite.net on the
same IP address:
<VirtualHost
*:80>
ServerAdmin blackhole@howtohostawebsite.net
DocumentRoot C:/_Live/
howtohostawebsite.net
ServerName www.howtohostawebsite.net
ServerAlias howtohostawebsite.net *.howtohostawebsite.net
CustomLog C:/_Live/logs/access_
howtohostawebsite_net.log combined
</VirtualHost>
Note: ServerAlias
ensures that if a user enters into their web browser http://howtohostawebsite.net or http://www.howtohostawebsite.net
then they will still both go to the same default.html page. This also requires that your DNS recognises
both forms of the domain name.
Note: You should only grant your
Apache user privileges to the directories where you store your web content and
to the directories mentioned above where the Apache binaries and logs are
stored.
Every time you make a change to the httpd.conf
file, ensure that you stop and start the Apache service.
Checking out that your website works
OK, so now that you have installed Apache, configured it to point
towards your own directory with web content, and started the service, then you
should have an up and running website!
Depending on the router that you have installed you may not be able to
access your website from within your own network using your domain name. If this is the case, a good way to test it
is to use a site like: www.anonymizer.com or if you have access
to another network over VPN, try connecting using your VPN client and loading
up a web browser.
Sometimes, again depending on the router, you can use http://xyz where xyz is the name of your computer. This will show the default website, but not
any virtual hosts.
After viewing your website open up your access_xxx.log
file (where xxx is what you have named is in the httpd.conf). You should see your own access requests
appearing.
If for some reason it did not work, 1st port of call is the error.log.
|