<?xml version="1.0" encoding="utf-8"?><!DOCTYPE article  PUBLIC '-//OASIS//DTD DocBook XML V4.4//EN'  'http://www.docbook.org/xml/4.4/docbookx.dtd'><article><articleinfo><title>htaccess</title><revhistory><revision><revnumber>2</revnumber><date>2013-06-27 14:36:39</date><authorinitials>ZioPRoTo</authorinitials></revision><revision><revnumber>1</revnumber><date>2013-06-27 14:36:11</date><authorinitials>ZioPRoTo</authorinitials></revision></revhistory></articleinfo><section><title>Apache: protect with username and password a web path</title><para>First of all in the apache config make sure you can Override the configuration with the hidden <code>.htaccess</code> files. In this example config I replaced <code>AllowOverride None</code> to <code>AllowOverride All</code> </para><screen><![CDATA[<Directory "/srv/http">
    #
    # 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"
    # doesn't give it to you.
    #
    # The Options directive is both complicated and important.  Please see
    # http://httpd.apache.org/docs/2.2/mod/core.html#options
    # for more information.
    #
    Options Indexes FollowSymLinks
]]><![CDATA[
    #
    # 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 None
    AllowOverride All 
]]><![CDATA[
    #
    # Controls who can get stuff from this server.
    #
    Order allow,deny
    Allow from all
]]><![CDATA[
</Directory>]]></screen><para>Restart apache if you change the apache configuration. </para><para>Now in the directory you want to protect create the hidden <code>.htaccess</code> file, here my example: </para><screen><![CDATA[[root@alarm ~]# cat /srv/http/.htaccess 
AuthType basic
AuthName REALM
AuthUserFile /etc/apachepwd
Require valid-user
]]><![CDATA[
[root@alarm ~]# ]]></screen><para>To create users in the <code>apachepwd file use the command htpasswd</code> </para><screen><![CDATA[htpasswd /etc/apachepwd myusername]]></screen></section></article>