How to Install OpenLDAP on Ubuntu 24.04
Introduction
OpenLDAP is a free and open-source implementation of the Lightweight Directory Access Protocol (LDAP). It provides a centralized directory service for storing user accounts, passwords, group information, and other directory data.
In this tutorial, we will install OpenLDAP on Ubuntu 24.04, configure phpLDAPadmin, create a basic LDAP structure, add a test user, and enable HTTPS with Let’s Encrypt.
Note: The domain example.com is used for demonstration purposes. Replace it with your own domain when following this guide.
Prerequisites
Before starting, you should have:
- Ubuntu 24.04
- Root or sudo access
- A domain pointing to your server
For this tutorial:
Domain: example.com Base DN: dc=example,dc=com Administrator DN: cn=admin,dc=example,dc=com
Create a Server Instance
Provision a clean Ubuntu 24.04 server with at least 2 CPUs, 2 GB RAM, and 20 GB SSD.
After deployment, note the server IP address.
Connect to Your Server via SSH
On Linux or macOS:
ssh root@your_server_ip
On Windows, use an SSH client such as PuTTY and connect as root.
Step 1: Update the System
apt update && apt upgrade -y
Step 2: Install OpenLDAP Server
Install OpenLDAP and the LDAP utilities:
apt install slapd ldap-utils -y
If the configuration wizard does not appear:
dpkg-reconfigure slapd
During reconfiguration, choose:
- Omit OpenLDAP server configuration? → No
- DNS domain name: example.com
- Organization name: Example Inc
- Admin password: choose a secure password
- Database backend: MDB
- Remove database when slapd is purged? → No
- Move old database? → Yes
The resulting Base DN is:
dc=example,dc=com
Step 3: Verify LDAP Server
Check the service:
systemctl status slapd
Test the LDAP server:
ldapsearch -x -LLL -b dc=example,dc=com
Step 4: Install phpLDAPadmin
Install phpLDAPadmin:
apt install phpldapadmin -y
Edit the configuration:
nano /etc/phpldapadmin/config.php
Update:
$servers->setValue('server','host','127.0.0.1');
$servers->setValue('login','bind_id','cn=admin,dc=example,dc=com');
Edit the Apache configuration:
nano /etc/apache2/conf-enabled/phpldapadmin.conf
Change:
Require local
to:
Require all granted
Restart Apache:
systemctl restart apache2
phpLDAPadmin can now be accessed through:
http://your_server_ip/phpldapadmin/
or, after DNS propagation:
http://example.com/phpldapadmin/
Step 5: Create Base LDAP Structure
Create the LDIF file:
nano base.ldif
Add:
dn: ou=people,dc=example,dc=com objectClass: organizationalUnit ou: people dn: ou=groups,dc=example,dc=com objectClass: organizationalUnit ou: groups
Import the structure:
ldapadd -x -D cn=admin,dc=example,dc=com -W -f base.ldif
Step 6: Add an LDAP User
Create the user file:
nano john.ldif
Add:
dn: uid=john,ou=people,dc=example,dc=com objectClass: inetOrgPerson sn: Doe givenName: John cn: John Doe uid: john mail: [email protected] userPassword: password
For production environments, use a strong password.
Generate a password hash with:
slappasswd
Then add the user:
ldapadd -x -D cn=admin,dc=example,dc=com -W -f john.ldif
Step 7: Enable HTTPS with Let’s Encrypt
Install Certbot:
apt install certbot python3-certbot-apache -y
Request an SSL certificate:
certbot --apache -d example.com
Choose the option to redirect HTTP traffic to HTTPS.
Final Access Points
phpLDAPadmin:
https://example.com/phpldapadmin/
Test LDAP:
ldapsearch -x -LLL -b dc=example,dc=com
The LDAP user created in this tutorial is:
uid=john,ou=people,dc=example,dc=com
Conclusion
OpenLDAP is now installed and configured on Ubuntu 24.04 with phpLDAPadmin, a basic LDAP directory structure, an LDAP user, and HTTPS enabled.
This setup can be used as a centralized LDAP directory for applications and services that support LDAP authentication.