Alex Rump
Alex Rump

Reputation: 1

Bitnami LDAP - PHP Error: ldap_bind(): Unable to bind to server: Invalid credentials

I am having some trouble with setting up an LDAP image in docker or more precisely to connect to said LDAP image.

I am currently working with the Bitnami Image and am using the following docker-compose.yml:

version: '3'
networks:
  my-network:
    driver: bridges
services:
  ldap:
    image: bitnami/openldap:latest
    restart: unless-stopped
    environment:
      - LDAP_ORGANISATION="My Company"
      - LDAP_DOMAIN="my-company.com"
      - LDAP_ROOT="dc=my-company,dc=com"
      - LDAP_ADMIN_USERNAME="admin"
      - LDAP_ADMIN_PASSWORD="adminpassword"
      - LDAP_USERS=user01,user02
      - LDAP_PASSWORDS=password1,password2
    ports:
      - '1389:1389'
      - '1636:1636'
    networks:
      - my-network
volumes:
  openldap_data:
    driver: local

I am trying to connect using a php file, which looks like this:

<?php

$uri = 'ldap://127.0.0.1:1389';
$user = 'cn=admin,dc=my-company,dc=com';
$pw = 'admin-password';



$ldapconn = ldap_connect($uri)
        or die("Could not connect to LDAP server.");


        ldap_set_option($ldapconn, LDAP_OPT_PROTOCOL_VERSION, 3);
        ldap_set_option($ldapconn, LDAP_OPT_REFERRALS, 0);

        if ($ldapconn) {

            // binding to ldap server
            $ldapbind = ldap_bind($ldapconn, $user, $pw);

            // verify binding
            if ($ldapbind) {
                echo "LDAP bind successful...";
            } else {
                echo "LDAP bind failed...";
            }

        }

Now I've not worked with LDAP before and am also fairly new to working with Docker, but I am honestly unsure, of what I am doing wrong. PHP throws the following Error:

*PHP Warning: ldap_bind(): Unable to bind to server: Invalid credentials in /Users/alex/Dev/phpdic/locean-intern/ldaptest.php on line 19

Warning: ldap_bind(): Unable to bind to server: Invalid credentials in /Users/alex/Dev/phpdic/locean-intern/ldaptest.php on line 19*

Am I doing something wrong or is something wrong with the image?

Upvotes: 0

Views: 1205

Answers (1)

Miguel Ruiz
Miguel Ruiz

Reputation: 121

I've noticed you have configured LDAP_ADMIN_PASSWORD="adminpassword" in your docker-compose while in your php file you set $pw = 'admin-password'; with a dash.

Does your issue persist after setting $pw = 'adminpassword';?

Upvotes: 0

Related Questions