Install and Configure phpLDAPadmin on CentOS 6

Install and Configure phpLDAPadmin on CentOS 6

phpLDAPadmin logo

phpLDAPadmin is a PHP web application for browsing and editing an LDAP directory. Instead of writing LDIF files and running ldapadd/ldapmodify, you can create OUs, users and groups, change attributes and export entries from a browser. It runs under Apache and talks to your OpenLDAP server (slapd) over LDAP.

Prerequisites

This blog assumes you went through the following setup steps up until this point: http://blog.zwiegnet.com/linux-server/configure-ldap-server-on-centos-6/

  • A working OpenLDAP server with a base DN (this example uses dc=mydomain,dc=com) and an admin DN with a password.
  • Root access on the server, and a workstation on your LAN to browse from.

1) Add the EPEL repository

login to your LDAP server and su to root

Root shell prompt on the LDAPDEMO server

wget the epel repo

wget http://mirror-fpt-telecom.fpt.net/fedora/epel/6/i386/epel-release-6-8.noarch.rpm

rpm -ivh epel-release-6-8.noarch.rpm installing the EPEL repository
rpm -ivh epel-release-6-8.noarch.rpm

phpLDAPadmin is not in the CentOS base repositories; EPEL (Extra Packages for Enterprise Linux) provides it. The mirror in the original command is long gone. EPEL 6 is archived, so on a CentOS 6 box you will need an archive mirror.

2) Install phpLDAPadmin

from here we need to install phpLDAPadmin

yum -y install phpldapadmin
yum -y install phpldapadmin

This pulls in httpd, PHP and php-ldap if they are not already installed.

3) Log in by DN instead of uid

from here edit the config file

vi /etc/phpldapadmin/config.php

un-comment line 397, comment line 398. It should look like so:

config.php line 397 login attr dn enabled and line 398 login attr uid commented out
$servers->setValue('login','attr','dn');
// $servers->setValue('login','attr','uid');

With attr = uid phpLDAPadmin expects a user name and searches for it, which fails for the directory admin because cn=admin has no uid attribute. With dn you log in with the full DN, for example cn=admin,dc=mydomain,dc=com. Line numbers vary between versions, so search for 'login','attr' if yours differ.

4) Allow your subnet in Apache

now we need to edit another config file

vi /etc/httpd/conf.d/phpldapadmin.conf

add your local subnet so you are able to view phpldapadmin

phpldapadmin.conf Allow from 127.0.0.1 192.168.1.0/24 in the htdocs Directory block

The package’s /etc/httpd/conf.d/phpldapadmin.conf creates the /phpldapadmin and /ldapadmin URLs and only allows 127.0.0.1 by default. Add your admin network to the Allow from line, as in Allow from 127.0.0.1 192.168.1.0/24. Keep it restricted. This page gives write access to your whole directory.

5) Start Apache

set Apache to start on startup, and then start the service

chkconfig httpd on and service httpd start
chkconfig httpd on
service httpd start

If iptables is running, allow port 80 (or better, set up https with mod_ssl, since your LDAP admin password is sent through this page).

6) Log in

now browse to the following URL:

http://serverhostname/ldapadmin

phpLDAPadmin home page with Local LDAP Server and login link

hit login

phpLDAPadmin login form with User Name cn=admin,dc=mydomain,dc=com

in the above box, type in the admin user, and use the slapd password (not the hash, but the phrase)

phpLDAPadmin tree for dc=mydomain,dc=com with cn=admin, ou=groups and ou=people

you should now be logged in! That’s it!

The “slapd password” is the clear-text password whose hash you put in olcRootPW/rootpw when building the server. Use the full admin DN as the user name.

Troubleshooting

  • 403 Forbidden: your workstation’s IP is not in the Allow from line, or you edited the file but did not restart httpd.
  • Tree shows “Logged in as: Anonymous (read only)”: you went in with an anonymous bind, not as the admin, so you cannot edit. Log out and log in with the admin DN. See disable OpenLDAP anonymous access if you do not want anonymous binds at all.
  • Invalid credentials (49): wrong DN or password. Test outside the browser with ldapwhoami -x -D "cn=admin,dc=mydomain,dc=com" -W.
  • Can’t contact LDAP server: slapd is not running, or with SELinux enforcing Apache is not allowed to open the connection. Run setsebool -P httpd_can_connect_ldap on.
  • Blank page: check /var/log/httpd/error_log, usually a missing php-ldap module.

RHEL, AlmaLinux and Rocky 9/10

Use dnf and systemd: dnf install epel-release, check that your EPEL release ships it with dnf info phpldapadmin, then systemctl enable --now httpd and firewall-cmd --permanent --add-service=http (plus --reload). Apache 2.4 replaces Order/Allow with Require, so the access line becomes Require ip 127.0.0.1 192.168.1.0/24.

Related guides

Configure OpenLDAP over TLS | Add an OU to OpenLDAP from the command line

Hosted Linux servers at www.zwiegnet.com/go

Leave a Reply

Your email address will not be published. Required fields are marked *