Skip to Content

How to install OpenLDAP and phpLDAPadmin on ubuntu?

Install OpenLDAP and LDAP Admin on Ubuntu

Make sure to set your system hostname and add it to file  /etc/hosts.  Replace admod.ezeelogin.com with your hostname or valid domain name.

root@ubuntu:~# hostnamectl set-hostname admod.ezeelogin.com
 
root@ubuntu:~#   vi /etc/hosts

192.168.1.11 admod.ezeelogin.com

 1) Install OpenLDAP packages
 

root@ubuntu:~#  apt update 

root@ubuntu:~#  apt -y install slapd ldap-utils

 
During the installation, you'll be prompted to set the LDAP admin password. Provide your desired password and press enter.
 
 
 
 
Confirm the password and continue the installation by pressing OK.
 
 
 
You can confirm that your installation was successful by using the command " slapcat ". It is used to fetch the SLAPD data content.
 

root@ubuntu:~# slapcat
dn: dc=com
objectClass: top
objectClass: dcObject
objectClass: organization
o: com
dc: com
structuralObjectClass: organization
entryUUID: 5eeea770-459c-103b-9cad-53d18c55e0b0
creatorsName: cn=admin,dc=com
createTimestamp: 20210510052901Z
entryCSN: 20210510052901.084178Z#000000#000#000000
modifiersName: cn=admin,dc=com
modifyTimestamp: 20210510052901Z

dn: cn=admin,dc=com
objectClass: simpleSecurityObject
objectClass: organizationalRole
cn: admin
description: LDAP administrator
userPassword:: e1NTSEF9Z0V1WnUzU2M5bENGcnJxWWFoZGtLRjNKc09DbFU3V3A=
structuralObjectClass: organizationalRole
entryUUID: 5eef2bf0-459c-103b-9cae-53d18c55e0b0
creatorsName: cn=admin,dc=com
createTimestamp: 20210510052901Z
entryCSN: 20210510052901.087602Z#000000#000#000000
modifiersName: cn=admin,dc=com
modifyTimestamp: 20210510052901Z

 
 Add base dn for Users and groups
 
Create a file named basedn.ldif and add the following contents. Replace ezeelogin and com with your domain components.
 

root@ubuntu:~# vi basedn.ldif

dn: ou=people,dc=ezeelogin,dc=com
objectClass: organizationalUnit
ou: people

dn: ou=groups,dc=ezeelogin,dc=com
objectClass: organizationalUnit
ou: groups

 

 
 Add the basedn file by running the following command 

root@ubuntu:~# ldapadd -x -D cn=admin,dc=ezeelogin,dc=com -W -f basedn.ldif
Enter LDAP Password:
adding new entry "ou=people,dc=ezeelogin,dc=com"

adding new entry "ou=groups,dc=ezeelogin,dc=com"


2) Install phpLDAPadmin on Ubuntu

Enter the following command to install LDAP and its dependencies.
 

root@ubuntu:~# apt -y install apache2 php php-cgi libapache2-mod-php php-mbstring php-common php-pear

 
Enable php*-cgi extension
Replace phpX.X with your PHP version.
 

root@ubuntu:~# a2enconf phpX.X-cgi
root@ubuntu:~#  service apache2 reload

 Install LDAP admin by running the following command

root@ubuntu:~# apt -y install phpldapadmin

 
To access phpLDAPadmin you've to use the following 
 

http://(server 's hostname or IP adress)/phpldapadmin

 
The following image shows the GUI of phpLDAPadmin
Click on " login" button at the top left corner of GUI to log in to the admin dashboard. 
 
 

NOTE: If you get the below error message on the dashboard, edit the  /etc/phpldapadmin/config.php file. Somewhere near line 300, you'll find the following lines, replace Example and com with your basedn to clear the error message. 

 

vi /etc/phpldapadmin/config.php

$servers->setValue('server','base',array('dc=example,dc=com'));

$servers->setValue('login','bind_id','cn=admin,dc=example,dc=com');

 
 
 
3) Creating groups in LDAP

Click on the create new child entry and select the Object which you want to create. 
 
 
Select  Generic: Posix Group and specify the group name in the text box, mark the checkbox if you want to add the users to the group. Finally, click on the create object tab to create the group in LDAP.

 
4) Create User in LDAP

Click on the create a child entry and select Generic: User Account.      Specify the username, select the GID Number from the drop-down menu, provide home directory, Password, user ID and then click on create Object to create the user. 
 
 

Related Articles: