# How to Install and Configure OpenLDAP Server on Ubuntu 16.04 Step by Step May 13, 2017Xiao Guoan3 CommentsUbuntuIn this tutorial, we are going to take a look at installing and Configuring OpenLDAP server on Ubuntu 16.04 LTS server. We will also install the phpLDAPadmin web-based management tool.

What is OpenLDAP

OpenLDAP is an open-source and fast directory server that provides network client with directory services. Client applications connect to OpenLDAP server using the Lightweight Directory Access Protocol (LDAP) to access organizational information stored on that server. Given the appropriate access, clients can search the directory, modify and manipulate records in the directory. OpenLDAP is efficient on both reading and modifying data in the directory.
OpenLDAP servers are most commonly used to provide centralized management of user accounts.

How to Install OpenLDAP Server on Ubuntu 16.04

Run the following command to install OpenLDAP server and the client command-line utilities from Ubuntu 16.04 package repository. slapd stands for the Stand-Alone LDAP Daemon. sudo apt install slapd ldap-utilsYou will be asked to set a password for the admin entry in the LDAP directory.
How to Install and Configure OpenLDAP Server on Ubuntu 16.04 Step by Step - 图1


Once it’s done, slapd will be automatically started. You can check out its status with: systemctl status slapdBe default, it runs as the openldap user as is defined in /etc/default/slapd file.

Basic Post-Installation Configuration

The installation process installs the package without any configurations. To have our OpenLDAP server running properly, we need to do some basic post-installation configuration. Run the following command to start the configuration wizard. sudo dpkg-reconfigure slapdYou will need to answer a series of questions. Answer these questions as follows:
Omit LDAP server configuration: NO.
How to Install and Configure OpenLDAP Server on Ubuntu 16.04 Step by Step - 图2
DNS domain name: Enter your domain name like linuxbabe.com. You will need to set a correct A record for your domain name. You can also subdomains like directory.linuxbabe.com. This information is used to create the base DN (distinguished name) of the LDAP directory.
How to Install and Configure OpenLDAP Server on Ubuntu 16.04 Step by Step - 图3
Organization name: Enter your organization name like LinuxBabe.
How to Install and Configure OpenLDAP Server on Ubuntu 16.04 Step by Step - 图4
Administrator password: Enter the same password set during installation.
How to Install and Configure OpenLDAP Server on Ubuntu 16.04 Step by Step - 图5
Database backend: MDB.
BDB (Berkeley Database) is slow and cumbersome. It is deprecated and support will be dropped in future OpenLDAP releases. HDB (Hierarchical Database) is a variant of the BDB backend and will also be deprecated.
MDB reads are 5-20x faster than BDB. Writes are 2-5x faster. And it consumes 1/4 as much RAM as BDB. So we choose MDB as the database backend.
How to Install and Configure OpenLDAP Server on Ubuntu 16.04 Step by Step - 图6
Do you want the database to be removed when slapd is purged? No.
How to Install and Configure OpenLDAP Server on Ubuntu 16.04 Step by Step - 图7
Move old database? Yes.
How to Install and Configure OpenLDAP Server on Ubuntu 16.04 Step by Step - 图8
Allow LDAPv2 protocol? No. The latest version of LDAP is LDAP v.3, developed in 1997. LDAPv2 is obsolete.
How to Install and Configure OpenLDAP Server on Ubuntu 16.04 Step by Step - 图9
Now the process will reconfigure the OpenLDAP service according to your answers. Your OpenLDAP server is now ready to use.
How to Install and Configure OpenLDAP Server on Ubuntu 16.04 Step by Step - 图10

Configuring the LDAP Clients

/etc/ldap/ldap.conf is the configuration file for all OpenLDAP clients. Open this file. sudo nano /etc/ldap/ldap.confWe need to specify two parameters: the base DN and the URI of our OpenLDAP server. Copy and paste the following text at the end of the file. Replace your-domain and com as appropriate. BASE dc=your-domain,dc=com URI ldap://localhostThe first line defines the base DN. It tells the client programs where to start their search in the directory. If you used a subdomain when configuring OpenLDAP server, then you need to add the subdomain here like so BASE dc=subdomain,dc=your-domain,dc=comThe second line defines the URI of our OpenLDAP server. Since the LDAP server and client are on the same machine, we should set the URI to ldap://localhost.

Testing OpenLDAP Server

Now that OpenLDAP server is running and client configuration is done, run the following command to make test connections to the server. ldapsearch -xOutput:

extended LDIF

#

LDAPv3

base (default) with scope subtree

filter: (objectclass=*)

requesting: ALL

#

linuxbabe.com

dn: dc=linuxbabe,dc=com objectClass: top objectClass: dcObject objectClass: organization o: LinuxBabe

admin, linuxbabe.com

dn: cn=admin,dc=linuxbabe,dc=com objectClass: simpleSecurityObject objectClass: organizationalRole cn: admin description: LDAP administrator

search result

search: 2 result: 0 Success

numResponses: 3

numEntries: 2Result: 0 Success indicates that OpenLDAP server is working. If you get the following line, then it’s not working.

result: 32 No such object## Installing phpLDAPadmin phpLDAPadmin is a web-based program for managing OpenLDAP server. The command-line utilities can be used to manage our OpenLDAP server, but for those who want an easy-to-use interface, you can install phpLDAPadmin.
Run the following command to install phpLDAPadmin from Ubuntu package repository. sudo apt install phpldapadminIf your Ubuntu server doesn’t have a web server running, then the above command will install the Apache web server as a dependency. If there’s already a web server such as Nginx, then Apache won’t be installed.

If you use Apache

The installation will put a configuration file phpldapadmin.conf under /etc/apache2/conf-enabled/ directory. Once the installation is done, you can access phpLDAPadmin web interface at your-server-ip/phpldapadminor your-domain.com/phpldapadminTo enable HTTPS, you can obtain and install a free TLS certificate issued from Let’s Encrypt.

If you use Nginx

Nginx users will need to manually create a server block file for phpLDAPadmin. sudo nano /etc/nginx/conf.d/phpldapadmin.confCopy the following text and paste it to the file. Replace ldap.your-domain.com with your preferred domain name. server { listen 80; server_name ldap.your-domain.com;

  1. root /usr/share/phpldapadmin/htdocs;
  2. index index.php index.html index.htm;
  3. error_log /var/log/nginx/phpldapadmin.error;
  4. access_log /var/log/nginx/phpldapadmin.access;
  5. location ~ \.php$ {
  6. fastcgi_pass unix:/run/php/php7.0-fpm.sock;
  7. fastcgi_index index.php;
  8. fastcgi_param SCRIPT_FILENAME $document_root/$fastcgi_script_name;
  9. include fastcgi_params;
  10. }

}Save and close the file. Then text Nginx configurations. sudo nginx -tIf the test is successful, reload Nginx for the changes to take effect. sudo systemctl reload nginxNow you can access phpLDAPadmin web interface at ldap.your-domain.com. To enable HTTPS, you can obtain and install a free TLS certificate issued from Let’s Encrypt.

Configuring phpLDAPadmin

We need to do some configurations just like we did with the command-line client. The phpLDAPadmin configuration file is at /etc/phpldapadmin/config.php . sudo nano /etc/phpldapadmin/config.phpSince OpenLDAP and phpLDAPadmin are running on the same machine, so we will configure phpLDAPadmin to connect to localhost on the default LDAP port 389 without SSL/TLS encryption.
Line 293 specifies that phpLDAPadmin will connect to localhost. $servers->setValue(‘server’,’host’,’127.0.0.1’);Line 296 is commented out by default, which means the standard port 389 will be used. // $servers->setValue(‘server’,’port’,389);Line 335 is commented out by default, which means TLS encryption is not enabled. // $servers->setValue(‘server’,’tls’,false);Then go to line 300. $servers->setValue(‘server’,’base’,array(‘dc=example,dc=com’));Change it to: $servers->setValue(‘server’,’base’,array());This will let phpLDAPadmin automatically detect the base DN of your OpenLDAP server. Next, you can disable anonymous login. Go to line 453. // $servers->setValue(‘login’,’anon_bind’,true);By default, anonymous login is enabled. To disable it, you need to remove the comment character (the two slashes) and change true to false. $servers->setValue(‘login’,’anon_bind’,false);You will probably want to disable template warnings because these warnings are annoying and unimportant. Go to line 161. // $config->custom->appearance[‘hide_template_warning’] = false;Remove the comment character and change false to true. $config->custom->appearance[‘hide_template_warning’] = true;Save and close the file.

Accessing phpLDAPadmin Web Interface

We can now test out the phpLDAPadmin tool with our web browser. When phpLDAPadmin first loads, it looks something like this.
How to Install and Configure OpenLDAP Server on Ubuntu 16.04 Step by Step - 图11
To log into our OpenLDAP server, click on the login link. You will see the login dialog box. The default login DN is cn=admin,dc=example,dc=com. You may need to change dc=example. In my case, I need to change the login DN to cn=admin,dc=linuxbabe,dc=com.
How to Install and Configure OpenLDAP Server on Ubuntu 16.04 Step by Step - 图12
The password is the admin password you set during the configuration of OpenLDAP server. Once you log into phpLDAPadmin, you can manage this directory server.
How to Install and Configure OpenLDAP Server on Ubuntu 16.04 Step by Step - 图13
That’s it! I hope this tutorial helped you install and configure both OpenLDAP server and phpLDAPadmin on Ubuntu 16.04. In the next tutorial, we will see how to configure Ubuntu to authenticate user logins with OpenLDAP.

Rate this tutorial[Total: 31 Average: 4.6]

Related posts:

  1. How to Install CouchPotato on Ubuntu 16.04/17.04 with Deluge
  2. How to Enable HTTP/2 Protocol with Apache on Ubuntu 16.04/17.10
  3. How to Install Sonerezh Music Streaming Server on Ubuntu 16.04 with Apache or Nginx
  4. How to Install MediaWiki on Ubuntu 16.04/17.04 with Apache or Nginx
  5. How to Properly Enable HTTPS on Apache with Let’s Encrypt on Ubuntu 16.04/17.10