/var/www/htdocsEdit your servers httpd.conf file and to tell apache which directory to protect. If you compiled apache your httpd.conf file will be located in /usr/local/apache/conf/httpd.conf. Using your favorite text editor (vi, pico, nano, etc.) edit the http.conf file and add the following (remember this is an example):
<Directory /var/www/htdocs/2> AllowOverride All Order allow,deny Allow from all </Directory>While you are editing your httpd.conf file make sure it has the following information in it:
AccessFileName .htaccess <Files ".ht"> Order allow,deny Deny from all Satisfy All </Files>Insert the following lines. These add the path to the directory we are trying to protect.
# # Controls who can get stuff from this server. > # > Order allow,deny Allow from all> <Directory /var/www/htdocs/> AllowOverride All > Order allow,deny Allow from all </Directory>
AuthName "Authorization required" AuthType Basic AuthUserFile4 /var/www/.htpasswd AuthGroupFile /dev/null require valid-userNote that the path /var/www/.htpasswd must be changed to suit your needs. Also bear in mind at this point the file .htpasswd has not been created.
cd /var/wwwUse a program called htpasswd. You will have to be root in this example.
sudo htpasswd -c /var/www/.htpasswd anywebThe htpasswd program will prompt for a password; enter it and then confirm it. Confirm the file is present (it is hidden remember)
ls -aLook inside the .htpasswd file.
sudo cat .htaccessDo you see?
$> anyweb:ARmbxDd.dEThe password string, ARmbxDd.dE, is an encrypted example. Yours will be different.
sudo /usr/local/apache/bin/apachectl stop sudo /usr/local/apache/bin/apachectl startBrowse 5to the server to the 'protected' directory, you will be prompted for a username/password if you followed the instructions !
http://httpd.apache.org/docs/1.3/mod/mod_access.html is required for using .htaccessEXAMPLE CODE IN http:conf:
LoadModule access_module /usr/lib/apache/1.3/mod_access.so2Notice the terminal slash! 3Notice the leading "." This file will be hidden becuase of the dot. There is no suffix, the file is simply ".htaccess." 4Please note: AuthUserFile must include an absolute path. `\"AuthUserFile .htpasswd `\" doesnt work if you have .htpasswd in your current directory. 5Please use a modern browser, like Firefox.