Apache: protecting directory content using .htpasswd 
Create htaccess definition file: /var/www/html/directory/.htaccess:

AuthType Basic
AuthName "Please enter username and password"
AuthUserFile /var/www/html/directory/.htpasswd
Require valid-user


Create new password file for the user and set initial password:

# htpasswd -c passwordfile username


cat /var/www/html/directory/.htpasswd
username:hAsHhaSH


Allow the apache to use the config in /etc/httpd/conf/httpd.conf:

<Directory>
#
# AllowOverride controls what directives may be placed in .htaccess files.
# It can be "All", "None", or any combination of the keywords:
# Options FileInfo AuthConfig Limit
#
AllowOverride All
</Directory>

#
# AccessFileName: The name of the file to look for in each directory
# for additional configuration directives. See also the
# AllowOverride directive.
#
AccessFileName .htaccess

#
# The following lines prevent .htaccess and .htpasswd files from
# being viewed by Web clients.
#
<Files ~ "^\.ht">
Order allow,deny
Deny from all
</Files>

<VirtualHost host.domain.cz:80>
AccessFileName /var/www/html/directory/.htaccess
DocumentRoot /var/www/html/directory/
ServerName domainname.dom
ServerAdmin administrator@domainname.dom
</VirtualHost>


Do not forget to edit the other AllowOverride

#
# AllowOverride controls what directives may be placed in .htaccess files.
# It can be "All", "None", or any combination of the keywords:
# Options FileInfo AuthConfig Limit
#
AllowOverride All


[ add comment ] ( 1 view )   |  [ 0 trackbacks ]   |  permalink

<<First <Back | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | Next> Last>>