How to Setup Apache Authentication using LDAP Active Directory

How to Setup Apache Authentication using LDAP Active Directory. In this post, we introduce Apache, its features, advantages and after we talk you through step by step process of how to setup Apache authentication using LDAP active directory.

What is Apache?

First of all, Apache is a free, open source web server software widely used to host websites on the internet. Developed and maintained by a community driven software organization Apache Foundation.

One of the key features of Apache is its support for multiple protocols, including HTTP, HTTPS, and FTP. Also, it has built in support for PHP, a popular programming language for developing dynamic websites. What is more, Apache also has several security features, such as support for SSL/TLS encryption, password protection, and access control.

Additionally, Apache is a reverse proxy server, load balancer, and HTTP cache. Often used in combination with other software, such as the MySQL database and the PHP programming language, to build powerful and dynamic websites.

Overall, Apache is a reliable and widely used web server that is suitable for a wide range of websites and applications. Specifically, active community of developers make it an attractive choice for many organizations and individuals looking to host websites on the internet.

Features of Apache

Many features of Apache make it a popular choice for hosting websites and applications on the internet. Some of the key features include:

  • Flexibility: Apache runs on a variety of operating systems, including Windows, Linux, and Mac OS. It is also highly customizable, with a wide range of modules added to extend its functionality.
  • Stability: A stable and reliable web server. Handles a large number of requests concurrently and recovers quickly from errors or crashes.
  • Security: With several security features, such as support for SSL/TLS encryption, password protection, and access control. It upgrades regularly to address any potential vulnerabilities.
  • Multiple Protocol Support: Supports multiple protocols, including HTTP, HTTPS, and FTP. Hence, it is a versatile choice for hosting a wide range of websites and applications.
  • Built in PHP Support: Apache has built in support for the PHP programming language, which is commonly used for developing dynamic websites. This way, it becomes easy to host PHP based applications on Apache.
  • Reverse Proxy and Load Balancing: Apache can be used as a reverse proxy server. It receives requests from clients and forwards them to other servers. Also used as a load balancer, distributing incoming requests across multiple servers to improve performance.
  • HTTP Caching: Apache configures as an HTTP cache, storing frequently requested content locally to reduce the load on the server and improve performance.
  • Open Source: Open source software, which means it is freely available for anyone to use and modify. It also has an active community of developers who contribute to the project, ensuring that it remains up to date and reliable.

Advantages of Apache

Some of the significant advantages of Apache are:

  • Free and Open Source – Apache is available to download and use for free, and its source code is open for anyone to review and modify. This makes it an attractive choice for individuals and organizations looking to host websites or applications on the internet.
  • Well Supported: Most popular web server software in the world, with a large user base and an active community of developers. Therefore, it is well tested and supported, with a wealth of resources available for users to learn from and troubleshoot issues.
  • Highly Customizable: With a wide range of modules, they can be added to extend its functionality. This way, it becomes suitable for a wide range of use cases and allows users to tailor it to their specific needs.
  • Stable and Reliable: Apache is known for its stability and reliability. It handles a large number of requests concurrently and can recover quickly from errors or crashes.

Now, we are at the main part of the article How to Setup Apache Authentication using LDAP Active Directory. Please follow up.

How to Setup Apache Authentication using LDAP Active Directory

This sections, shows you how to setup Apache authentication using LDAP active directory.

Prerequisites

  • A server with LDAP Active Directory installed and configured.
  • An Ubuntu server is installed on your system.
  • A root user or a user with sudo privileges.

Install Apache Web Server

First, you will need to install the Apache web server on your system. You can install it by running the following command.

				
					apt-get install apache2 apache2-utils -y
				
			

After installing the Apache package, start the Apache service and enable it to start after the system reboot.

				
					systemctl start apache2
systemctl enable apache2
				
			

Now, verify the Apache version using the following command.

				
					apache2ctl -V
				
			

You should get the Apache version in the following output.

				
					Server version: Apache/2.4.52 (Ubuntu)
Server built: 2022-09-30T04:09:50
Server's Module Magic Number: 20120211:121
Server loaded: APR 1.7.0, APR-UTIL 1.6.1
Compiled using: APR 1.7.0, APR-UTIL 1.6.1
Architecture: 64-bit
				
			

At this point, the Apache web server is installed and configured on your system. You can now proceed to create a sample file to host on the Apache web server.

Create a Simple HTML Page

Next, you need to create a simple test page to host on your web server. First, create a directory to host a website with the following command.

				
					mkdir /var/www/html/ldap
				
			

After that, create an index.html page using the following command.

				
					nano /var/www/html/ldap/index.html
				
			

Add the following HTML code:

				
					<html>
<body>
<div style="width: 100%; font-size: 50px; font-weight: bold; text-align: center;">
Congratulations! Apache web server is now configured with LDAP Active Directory Authentication.
</div>
<script>class RocketElementorAnimation{constructor(){this.deviceMode=document.createElement("span"),this.deviceMode.id="elementor-device-mode-wpr",this.deviceMode.setAttribute("class","elementor-screen-only"),document.body.appendChild(this.deviceMode)}_detectAnimations(){let t=getComputedStyle(this.deviceMode,":after").content.replace(/"/g,"");this.animationSettingKeys=this._listAnimationSettingsKeys(t),document.querySelectorAll(".elementor-invisible[data-settings]").forEach(t=>{const e=t.getBoundingClientRect();if(e.bottom>=0&&e.top<=window.innerHeight)try{this._animateElement(t)}catch(t){}})}_animateElement(t){const e=JSON.parse(t.dataset.settings),i=e._animation_delay||e.animation_delay||0,n=e[this.animationSettingKeys.find(t=>e[t])];if("none"===n)return void t.classList.remove("elementor-invisible");t.classList.remove(n),this.currentAnimation&&t.classList.remove(this.currentAnimation),this.currentAnimation=n;let s=setTimeout(()=>{t.classList.remove("elementor-invisible"),t.classList.add("animated",n),this._removeAnimationSettings(t,e)},i);window.addEventListener("rocket-startLoading",function(){clearTimeout(s)})}_listAnimationSettingsKeys(t="mobile"){const e=[""];switch(t){case"mobile":e.unshift("_mobile");case"tablet":e.unshift("_tablet");case"desktop":e.unshift("_desktop")}const i=[];return["animation","_animation"].forEach(t=>{e.forEach(e=>{i.push(t+e)})}),i}_removeAnimationSettings(t,e){this._listAnimationSettingsKeys().forEach(t=>delete e[t]),t.dataset.settings=JSON.stringify(e)}static run(){const t=new RocketElementorAnimation;requestAnimationFrame(t._detectAnimations.bind(t))}}document.addEventListener("DOMContentLoaded",RocketElementorAnimation.run);</script></body>
</html>

				
			

Save and close the file then change the ownership and permission of your website directory.

				
					chown -R www-data:www-data /var/www/html/ldap
chmod -R 755 /var/www/html/ldap

				
			

Once you are done, you proceed to configure the Apache web server.

Configure Apache for Active Directory LDAP Authentication

Now, you will need to create an Apache virtual host configuration file and define your LDAP Active directory authentication.
You can create it with the following command.

				
					nano /etc/apache2/sites-available/ldap.conf
				
			

Add the following configurations:

				
					<VirtualHost *:80>
ServerAdmin webmaster@localhost
ServerName ldap.example.com
DocumentRoot /var/www/html/ldap
DirectoryIndex index.html
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
<Directory "/var/www/html/ldap">
Options Indexes FollowSymlinks
AuthType Basic
AuthName "Apache LDAP authentication"
AuthBasicAuthoritative Off
AuthBasicProvider ldap
AuthLDAPURL "ldap://ldap-server-ip/CN=Users,DC=example,DC=local?sAMAccountName?sub?(objectClass=*)"
AuthLDAPBindDN "bind@example.local"
AuthLDAPBindPassword securepassword..
Require valid-user
</Directory>
</VirtualHost>

				
			

Save and close the file when you are done. Then, verify the Apache for any configuration error with the following command.

				
					apachectl -t
				
			

You should get the following output:

				
					Syntax OK
				
			

Next, enable the LDAP module with the following command.

				
					a2enmod authnz_ldap
				
			

After that, activate the Apache virtual host configuration file using the following command.

				
					a2ensite ldap.conf
				
			

Finally, restart the Apache service to apply the configuration changes.

				
					systemctl restart apache2
				
			

Verify Apache LDAP Authentication

At this point, the Apache web server is configured with LDAP Active directory authentication. Now, it’s time to test it. Open your web browser and access the Apache sample page using the URL http://ldap.example.com. You will be asked to provide your LDAP username and password as shown below.

Provide your LDAP username, password and click on the Sign In button. Once you are successfully authenticated with LDAP, you should see your sample HTML page on the following screen.

Thank you for reading How to Setup Apache Authentication using LDAP Active Directory. We shall conclude this article blog. 

How to Setup Apache Authentication using LDAP Active Directory Conclusion

In this post, you have learned how to set up Apache with LDAP Active directory authentication on Ubuntu. You can now use this setup in the production environment to restrict users to access your Apache web server.

Finally, Apache is known for its flexibility, stability, and security. It runs on various operating systems, including Windows, Linux, and Mac OS. It is also highly customizable, with a wide range of modules that can be added to extend its functionality. This makes it suitable for a wide range of use cases, including hosting small personal websites, large corporate websites, and even cloud based applications.

To check out more Apache content, please navigate to our blog over here

Avatar for Hitesh Jethva
Hitesh Jethva

I am a fan of open source technology and have more than 10 years of experience working with Linux and Open Source technologies. I am one of the Linux technical writers for Cloud Infrastructure Services.

0 0 votes
Article Rating
Subscribe
Notify of
0 Comments
Most Voted
Newest Oldest
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x