Modules needed for htaccess authentication in Apache 2.2

If you want to use .htaccess based user authentication (with the HTTP Basic method) like this:
AuthUserFile passwdfile
AuthName "Secured area"
AuthType Basic
Require valid-user

then you'll need at least the following modules in your Apache config:
  • mod_auth_basic
  • mod_authn_file
  • mod_authz_user
In case of a Debian server you can enable these modules with the following commands:
a2enmod mod_auth_basic
a2enmod mod_authn_file
a2enmod mod_authz_user
invoke-rc.d apache2 force-reload

If you're missing any of these modules and have a .htaccess in a directory with user-authentication enabled, then you'll most probably get HTTP 500 (Internal Server Error) upon accessing that directory through Apache. In the Apache error log you will find messages like these:
"client denied by server configuration"
or "configuration error: couldn't check user. No user file?"
or "configuration error: couldn't check access. No groups file?"