How to enable PHP LDAP in Azure Web Apps
PHP LDAP extension is not enabled by default in Azure Web App, you need the following steps:
How to enable extensions in the default PHP runtime
- Go to https://portal.azure.com
- Select your web app and go to App Settings
- Add an app setting called PHP_INI_SCAN_DIR with value d:\home\site\ini
- Go to Kudu Console https://<yourwebappname>.scm.azurewebsites.net/DebugConsole
- Navigate to site and create a new folder called ini with mkdir ini command.
- Create the file extensions.ini inside this folder with touch extensions.ini command.
- Write the following line: extension=php_ldap.dll
- Restart the web app and test.
You can check LDAP Documentation for more information: https://php.net/manual/en/function.ldap-bind.php
// Authentication example
$ldaprdn = 'uname'; // ldap rdn or dn
$ldappass = 'password'; // associated password
// Connection to LDAP server
$ldapconn = ldap_connect("ldap.example.com")
or die("Could not connect to LDAP server.");
if ($ldapconn) {
$ldapbind = ldap_bind($ldapconn, $ldaprdn, $ldappass);
if ($ldapbind) {
echo "LDAP bind successful...";
} else {
echo "LDAP bind failed...";
}
}