This guide will show you how to integrate Windows Active Directory authentication in Apache on Ubuntu 20.04. These instruction can also be applied if you are running Ubuntu 18.04, Debian 9, or Debian 10 on your system.
Prerequisites
To follow this tutorial along, you will need one (physical or virtual) machine installed with Ubuntu 20.04.
We have also created a video to avoid any confusion while performing these configuration steps:
Login to your Ubuntu system and set correct hostname and timezone with below command:
Install Apache
You can install Apache on your Ubuntu/Debian with below command:
Configure Apache
We will create a directory under /var/www/html to store our web contents.
We will create AD-ldap.conf file under /etc/apache2/conf-available location like an example below:
add configuration directives like an example below:
Make sure you replace highlighted text with yours.
By default Windows Active Directory doesn't allow anonymous lookup for LDAP database, so we have to put AuthLDAPBinDN and AuthLDAPBindPassword directive to allow Apache to search Active Directory for users credentials.
Save and close the editor when you are finished.
The actual AD-ldap.conf file in our environment looks like below:
![](http://1.bp.blogspot.com/-mhdkpbDZkHg/YFMigsHhROI/AAAAAAAATRI/VtNAZLt3i3c38kQjC1872OHbxdxtWJwYwCLcBGAsYHQ/s16000/Apache_Active_Directory_Authentication_6.jpg)
Verify your Apache configuration file syntax with below command:
This will return Syntax OK in the output if everything was setup correctly. If there is any error, fix them first then move to next step.
Execute below command to activate your Apache configuration:
Restart Apache to make changes effect:
We will create a simple index.html page under /var/www/html/private directory to test our Apache and Active Directory authentication functionality.
Add below simple html code in it:
Test Apache & Active Directory Authentication
Open up your preferred web browser, and navigate to:
http://your_server_name-OR_IP/private
or
https://your_server_name-OR_IP/private
You will get credentials popup as shown in screenshot below:
![](http://1.bp.blogspot.com/-I_ghaVLW_c0/YFGnxWw3NrI/AAAAAAAATP8/YLcgzLqjab428CSENhkhVi_4db7sRSgtgCLcBGAsYHQ/s16000/Apache_Active_Directory_Authentication.jpg)
Enter your Active Directory username and password like example below:
![](http://1.bp.blogspot.com/-iihbyQ_Dj1c/YFGoQ8wof6I/AAAAAAAATQE/e5o0XayqCSIr4JKIM7nuMH7Z_N38IBHawCLcBGAsYHQ/s16000/Apache_Active_Directory_Authentication_1.jpg)
Upon successful login with your AD credentials, you should see the webpage like an example below:
![](http://1.bp.blogspot.com/-z6F3H_as-4o/YFGpDiMpKXI/AAAAAAAATQM/r1siUThHhzka1p8L5yl0o-6NHlaxyEDXwCLcBGAsYHQ/s16000/Apache_Active_Directory_Authentication_2.jpg)
Check your Apache access_log with below command:
You will see your Active Directory username in logs as shown in screenshot below:
![](http://1.bp.blogspot.com/-PMLN0GC6Fvw/YFGqFdVrGNI/AAAAAAAATQU/2QH3E0Grx44aYjyc5WI-Hyq1XIk_CwSLgCLcBGAsYHQ/s16000/Apache_Active_Directory_Authentication_3.jpg)
At this stage, you have successfully implemented Active Directory authentication in your Apache.
Troubleshooting
If you get 500 Internal Server Error in browser, you should check the Apache error_log using tail -f /var/log/apache2/error.log to identify the root cause.
Conclusion
By leveraging the central user management of Windows Active Directory, you don’t need to worry about usernames or passwords for your Apache web server anymore.