OpenLDAP is a free and open source implementation of the Lightweight Directory Access Protocol developed by the OpenLDAP Project. OpenLDAP is released under OpenLDAP Public License. In this guide, we’ll look at how to install OpenLDAP and phpLDAPadmin on Ubuntu 22.04|20.04|18.04 LTS, and later add user accounts for central authentication in your Network.
If you need advanced centralized user management platform, see
- How to Install and Configure FreeIPA Server on Ubuntu
- How to Configure FreeIPA Client on CentOS/Ubuntu
- How to Configure FreeIPA replication on Ubuntu / CentOS
What is phpLDAPadmin?
phpLDAPadmin is a web-based PHP application for administering Lightweight Directory Access Protocol servers. phpLDAPadmin is licensed under the GNU General Public License.
This tool exists to ease your OpenLDAP administration often done through commands such asldapadd,ldapdelete, ldapmodify, ldapsearch
e.t.c.
Step 1: Install OpenLDAP Server
We’ll start with the installation of OpenLDAP on Ubuntu 22.04|20.04|18.04 LTS. Set your system hostname and add it to file/etc/hosts
.
$ sudo hostnamectl set-hostname ldap.example.com
$ sudo vim /etc/hosts
192.168.18.50 ldap.example.com
Replace ldap.example.com
with your correct hostname/valid domain name.
logout
The OpenLDAP packages are available on Ubuntu 20.04|18.04 upstream repositories, and you install them by just firing apt install commands.
sudo apt update
sudo apt -y install slapd ldap-utils
During the installation, you’ll be prompted to set LDAP admin password
, provide your desired password, then press <OK>
Confirm the password and continue installation by selecting <ok> with TAB key.
You can confirm that your installation was successful using the commandslapcat
to output SLAPD database contents.
$ sudo slapcat
dn: dc=example,dc=com
objectClass: top
objectClass: dcObject
objectClass: organization
o: example.com
dc: example
structuralObjectClass: organization
entryUUID: 3096cde2-64b5-103c-836e-1d0b0995a781
creatorsName: cn=admin,dc=example,dc=com
createTimestamp: 20220510135944Z
entryCSN: 20220510135944.468673Z#000000#000#000000
modifiersName: cn=admin,dc=example,dc=com
modifyTimestamp: 20220510135944Z
Step 2: Add base dn for Users and Groups
The next step is adding a base DN for users and groups. Create a file named basedn.ldif
with below contents:
$ vim basedn.ldif
dn: ou=people,dc=example,dc=com
objectClass: organizationalUnit
ou: people
dn: ou=groups,dc=example,dc=com
objectClass: organizationalUnit
ou: groups
Replace example and com
with your correct domain components.
Now add the file by running the command:
$ sudo ldapadd -x -D cn=admin,dc=example,dc=com -W -f basedn.ldif
Enter LDAP Password:
adding new entry "ou=people,dc=example,dc=com"
adding new entry "ou=groups,dc=example,dc=com"
Step 3: Install phpLDAPadmin on Ubuntu
Once we have OpenLDAP running, it is time to install phpLDAPadmin which will help you manage your LDAP server. phpLDAPadmin requires PHP and Apache web server installed on your Ubuntu system.
sudo apt -y install apache2 php php-cgi libapache2-mod-php php-mbstring php-common php-pear
Enable php*-cgi
extension
sudo a2enconf php*-cgi
sudo systemctl reload apache2
Install phpLDAPadmin by running the command:
sudo apt -y install phpldapadmin
Modify access permissions on /etc/apache2/conf-enabled/phpldapadmin.conf
to allow access only from your trusted subnets.
$ sudo vim /etc/apache2/conf-enabled/phpldapadmin.conf
Order deny,allow
Deny from all
Allow from 127.0.0.1 192.168.18.0/24
Where 192.168.18.0/24 is the subnet to access it form.
You’ll need to restart apache web server after making the change:
sudo systemctl restart apache2
If you have active UFW firewall, open port 80
and port 443
sudo ufw allow proto tcp from any to any port 80,443
To access phpLDAPadmin, you’ve to access:
http://(server’s hostname or IP address)/phpldapadmin/
#Example
http://192.168.200.46/phpldapadmin/
Use a client machine allowed from the network to access the dashboard.
Click the “login” button at the top left corner to login to the admin dashboard.
Login DN: cn=admin,dc=example,dc=com Password: Use the admin password configured earlier.
Step 4: Install LDAP Account Manager – Recommended
I noticed phpLDAPadmin doesn’t work well with PHP 7 which is a default version of PHP on Ubuntu 22.04|20.04|18.04. I recommend you use LDAP Account Manager instead.
Follow our guide below to install and configure LDAP Account Manager on Ubuntu 22.04|20.04|18.04.
The guide also shows you how to add user accounts and groups to your LDAP server.
Step 5: Configure your Ubuntu as LDAP Client
The last step is to configure the systems in your network to authenticate against the LDAP server we’ve just configured:
Wrapping Up
Thanks for installing and configuring your LDAP authentication environment using our guides. Until next time, I want to thank you for visiting. Don’t forget to follow us on social media to get the latest updates.