password protect a directory

Discussion in 'Apache' started by andre75, Feb 17, 2007.

  1. #1
    I am trying to password direct a directory with apache2.
    I have put an .htaccess file in the dir:
    AuthUserFile /path/to/htpwd/.htpasswd
    AuthGroupFile /dev/null
    AuthName "my password page"
    AuthType Basic
    
    <Limit GET POST>
    require valid-user
    </Limit>
    
    Code (markup):
    with the acual path to .htpasswd.
    I created a user with htpasswd command.
    When I browse to the directory that has the .htaccess file in it I am not being asked for a password or anything.
    Do I need to install a module or change any of the config files?
     
    andre75, Feb 17, 2007 IP
  2. andre75

    andre75 Peon

    Messages:
    1,203
    Likes Received:
    45
    Best Answers:
    0
    Trophy Points:
    0
    #2
    I tried loading all the auth modules (like auth_ldap) but that didn't do anything.
     
    andre75, Feb 17, 2007 IP
  3. scdc

    scdc Peon

    Messages:
    31
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    This is work for me :

    AuthType Basic
    AuthName "page_name_here"
    AuthUserFile /path_to/apache22/passwd/file_name
    Require user "user_name_here"
     
    scdc, Feb 17, 2007 IP
  4. andre75

    andre75 Peon

    Messages:
    1,203
    Likes Received:
    45
    Best Answers:
    0
    Trophy Points:
    0
    #4
    That doesn't work either. May I ask what modules you have loaded?
     
    andre75, Feb 17, 2007 IP
  5. apachehtaccess

    apachehtaccess Guest

    Messages:
    82
    Likes Received:
    10
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Add this to your httpd.conf (if on non-windows) but I would imagine that these are already loaded.

    LoadModule access_module lib/modules/mod_access.so
    LoadModule auth_module lib/modules/mod_auth.so
    LoadModule auth_anon_module lib/modules/mod_auth_anon.so
    LoadModule auth_dbm_module lib/modules/mod_auth_dbm.so
    LoadModule auth_digest_module lib/modules/mod_auth_digest.so
    Code (markup):

    Then add a .htaccess file in the directory you want to protect with the following.

    AuthType Basic
    AuthName "Restricted Files"
    AuthUserFile /path/to/htpwd/.htpasswd
    Require valid-user
    Code (markup):
    CHMOD your .htaccess file 644 which translates to rw-r-r

    If you are on linux/bsd then goto a shell and cd into the directory that the .htaccess file is located in and type
    dos2unix -dv .htaccess
    Code (markup):
    which will get rid of any windows formatting, which often is the problem.

    Finally Make sure that in your httpd.conf file in the <Directory> code for your docroot or public_html directory you see at least the following after the AllowOverride directive:
    AllowOverride AuthConfig Limit
    Code (markup):

    Once its working then you can use this online htpasswd generator for your .htpasswd file.

    P.S. Don't use the <Limit> Directive.. you probably will never have to use that.

    If all this doesn't work than provide more info :)
     
    apachehtaccess, Feb 18, 2007 IP
    andre75 likes this.
  6. andre75

    andre75 Peon

    Messages:
    1,203
    Likes Received:
    45
    Best Answers:
    0
    Trophy Points:
    0
    #6
    EDITED: I almost got it working. Its asking for the password but won't accept the answer yet. I will be back letting you know (turns out its a bit different for apache2)

    Wow. Thanks a lot. Unfortunately it still doesn't work. I will try to give some more information.
    I am using Apache2 on Debian (Sarge) on a home server. I have full access and can install and uninstall whatever I like.

    No they were not. In Apache2 on Debian I simply link from mods-enabled to mods-available in order to laod a module.
    
    debianbox:/etc/apache2/mods-enabled# ln -s ../mods-available/auth_ldap.load 
    debianbox:/etc/apache2/mods-enabled# ln -s ../mods-available/auth_dbm.load 
    debianbox:/etc/apache2/mods-enabled# ln -s ../mods-available/auth_digest.load 
    debianbox:/etc/apache2/mods-enabled# ln -s ../mods-available/auth_anon.load 
    
    Code (markup):
    I couldn't find mod_access (via apt-cache search). And mod_auth isn't there either. Maybe they are called something else on apache2?
    Done that.
    I created all the files on the linux machine directly
    I have to modify /etc/apache2/apache2.conf (not sure if thats debian or apache2 specific).
    I have this in apache2.conf:
    
    <Directory /var/www>
            AllowOverride All
    </Directory>
    
    Code (markup):
    The directory I am trying to protect is nunderneath this path (/var/www/somedir)
    I used
    
    htpasswd -c /path/to/.htpasswd user
    
    Code (markup):
    this tool comes with the apache2-common package I believe.
    I changed the config files as indicated above (removed the <Limit>).

    I am using the prefork version of apache2 (the worker doesn't work with php).
     
    andre75, Feb 18, 2007 IP
  7. apachehtaccess

    apachehtaccess Guest

    Messages:
    82
    Likes Received:
    10
    Best Answers:
    0
    Trophy Points:
    0
    #7
    What does the command apache2ctl -l or apache2 -l tell you?

    Compiled in modules:
       core.c
       mod_access.c
       mod_auth.c
    Code (markup):

    What is the result of this command? ls -la /etc/apache2/mods-available/


    Run the command a2enmod to see a list of modules you can install.

    After you make changes reload your apache instance. /etc/init.d/apache2 reload
     
    apachehtaccess, Feb 18, 2007 IP