Apache Access Configuration and Errors

To set up access restriction using Apache’s built-in access configuration feature you would need to update three files:

  1. Main Apache configuration file (httpd.conf): Make sure the Directory section of the file that refers to your website folder has “AllowOverride All” or at least “AllowOverride AuthConfig”. For example,

    <Directory “/home/websites/securedsite”>
    AllowOverride AuthConfig
    </Directory>

  2. Password file (.htpasswd): You can use the Apache’s built-in htpasswd tool to encrypt passwords. This utility should be located under the /bin/ folder. Type in “htpasswd” for all the options and more help on this tool. For each user a line such as “user1:RsQvdHxiKcH5w” should be added to your password file. The password file can have any arbitrary name and would be normally located in the top-most folder of your website that is supposed to be password protected. Give read permission to this file.
  3. Access Configuration File (.htaccess): This file sets up the authentication for our purpose. It can in fact contain any allowed customization at the folder level. Here is an example:
    AuthUserFile /home/websites/securedsite/.htpasswd
    AuthType Basic
    AuthName “Restricted Website”
    require valid-user

Some errors (in your Apache error log) that you may come across while setting up this access control include:

  • configuration error:  couldn’t perform authentication. AuthType not set!
    This tells you that “AuthType” parameter is not set in your .htaccess file.
  • Permission denied: /home/websites/securedsite/.htaccess pcfg_openfile: unable to check htaccess file, ensure it is readable
    The file .htaccess does not have the proper read permission.
  • Permission denied: Could not open password file: /home/websites/securedsite/.htpasswd
    The file .htpasswd does not have the proper read permission.
  • No such file or directory: Could not open password file: /home/websites/securedsite/.htpaswd
    The path to the .htpasswd file is not correct. A typo maybe?
  • configuration error:  couldn’t check user.  No user file?
    This probably tells you that the AuthType is not properly set (in my case, I had to change it from “Digest” to “Basic”).
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: