| Dieser Inhalt in deutsch |

Apache webserver - protect a directory

For a better presentation I added blank singns befor '\' and '/' .

Goal

A directory on an apache webserver running in windows has to be protected by username an password.

I used an apache webserver, as described at http://www.apachefriends.org /de /xampp.html with xampp.

I installed xampp on a test system at e:\programs \webserver \xampp\. All files of the website are stored in the folder htdocs and below. Also installed is a folder e:\programs \webserver \xampp \htdocs \forbidden. In this folder forbidden are two importand fildes: .htaccess and .htpasswd. This folder forbidden I use as an example. Die files .htaccess and .htpasswd are necessary to protect the folder.

File .htaccess

Such a file can not be created under windows. After the installation one of these files is stored in the folder /forbidden (in my installation e:\programs \webserver \xampp \htdocs \forbidden). So I copied this file an edited it. I changed the pathes so that it machtes to the view from the erver on his local files. AuthName is the name of the area which will be protected. You will be asked for username and password if you want to access this area.
You can create an edit this file with a text editor namig it htaccess.txt and later using an ftp programm to rename it to .htaccess.

AuthType Basic
AuthName "FORBIDDEN AREA"
AuthUserfile "../htdocs/forbidden/.htpasswd"
Require valid-user

Now the folder forbiddenwill be protected

Creating the file .htpasswd

In the folder e:\programs\webserver\xampp\apache\bin is the file htpasswd.exe. With this file usernames and password are created. Open the command line an move to e:\programme \webserver \xampp \apache \bin.

E:\Programs\webserver \xampp \apache \bin>[line break]
[enter command] htpasswd e:\programs \webserver \xampp \htdocs \forbidden \.htpasswd username [return]

Automatically using MD5 format.
New password: ***** [return]
Re-type new password: ***** [return]
Adding password for user username

E:\Programs\webserver\xampp\apache\bin>

What ist typed after [enter command] refers to the folder to be protected from the perspective of the operating system.

instead of 'username' type an appropriate username.

If the file .htpasswd ist not present type htpasswd -c to create it

e:\programs \webserver \xampp \apache \bin>[Umbruch]
[Type]htpasswd -c e:\programme \webserver \xampp \[line break]
htdocs\forbidden\.htpasswd username [return]


Automatically using MD5 format.
New password: ***** [return]
Re-type new password: ***** [return]
Adding password for user username


E:\Programs\webserver\xampp\apache\bin>