Apache can authenticate users via .htaccess files. Inside an intranet, for example, it is often useful to add a lightweight authentication layer to filter who can reach a web application. This article shows how to set up LDAP authentication on an Apache server.
First enable the module shipped with apache2:
a2enmod authnz_ldap
service apache2 force-reload
The configuration is set at the VirtualHost level, inside a Directory section. Add the following lines to the configuration of the directory you want to protect:
<Directory /private>
# <your VHost configuration>
AuthType basic
AuthName "Acces Restreint"
AuthBasicProvider ldap
AuthLDAPURL ldap://ldap.domain.tld/ou=people,dc=domain,dc=tld?uid
AuthLDAPRemoteUserIsDN off
require ldap-filter &(uid=*)
</Directory>
This configuration lets every user under the people branch of the domain.tld server authenticate against LDAP.
Finally reload the apache service:
service apache2 reload