- Install:
- Windows server 2019
- Make windows server IP static: In Virtualbox, Machine -> Settings -> Network -> Bridged Adapter
- We will need these information:
- Server IP address: (you can get it using "ipconfig" command)
- Admin username: (Example: Administrator)
- Admin password: (Example: 123456789A@)
- LDAP rdn: you can use this command in Windows server
C:\> dsquery user -samid Administrator
"cn=Administrator,cn=Users,dc=server,dc=local"
- Test connection using this PHP code
<?php
// using ldap bind
$ldaprdn = 'cn=Administrator,cn=Users,dc=server,dc=local'; // dn
$ldappass = '123456789A@'; // user password
$ldaphost = "192.168.1.20"
// connect to ldap server
$ldapconn = ldap_connect($ldaphost) or die("Could not connect to LDAP server.");
// Set some ldap options for talking to
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, $ldaprdn, $ldappass);
// verify binding
if ($ldapbind) {
//echo "LDAP bind successful...\n";
echo "Success";
} else {
//echo "LDAP bind failed...\n";
echo "Error";
}
}
Note from https://www.php.net/manual/en/ldap.installation.php:
In order for this extension to work, there are DLL files that must be available to the Windows system PATH. For information on how to do this, see the FAQ entitled "How do I add my PHP directory to the PATH on Windows". Although copying DLL files from the PHP folder into the Windows system directory also works (because the system directory is by default in the system's PATH), this is not recommended. This extension requires the following files to be in the PATH: libeay32.dll and ssleay32.dll, or, as of OpenSSL 1.1 libcrypto-.dll and libssl-.dll
- Install Adldap2-Laravel
composer require adldap2/adldap2-laravel
- Run:
php artisan vendor:publish --provider="Adldap\Laravel\AdldapServiceProvider"
- in ".env":
LDAP_LOGGING=true
LDAP_HOSTS=192.168.1.20 //Server Address
LDAP_BASE_DN=dc=server,dc=local //domain
LDAP_TIMEOUT=30
LDAP_USERNAME=Administrator@server.local //admin username + @ domain
LDAP_PASSWORD=123456789A@ // admin password
- Create a function in any Controller to test connection:
public function test_ad()
{
try {
$test_user = 'test@server.local';
$test_pass = '123456789A@';
Adldap::connect('default', $test_user, $test_pass);
return "Login/pass is correct";
// Great, we're connected!
} catch (Adldap\Auth\BindException $e) {
// Failed to connect.
return "Incorrect Login/pass";
}
}