我在apache服务器上有一个PHP脚本,每次我尝试运行它时,它都会告诉我:
unable to bind to the AD
不过连接良好。我把它从apache服务器上取下来,从我的机器上本地运行,它能够很好地绑定。我假设我的apache配置有问题。
我正在使用adLDAP API,这是我尝试运行的以下脚本。这基本上是一个测试,看看我是否能够成功绑定,并检查输入的凭据是否在Active Directory中。
$username = $_POST["username"];
$password = $_POST["password"];
$formage = $_POST["formage"];
if ($_POST["oldform"]) { //prevent null bind
if ($username != NULL && $password != NULL){
//include the class and create a connection
include (dirname(__FILE__) . "/../src/adLDAP.php");
try {
$adldap = new adLDAP();
}
catch (adLDAPException $e) {
echo $e;
exit();
}
//authenticate the user
if ($adldap->authenticate($username, $password)){
//establish your session and redirect
session_start();
$_SESSION["username"] = $username;
$_SESSION["userinfo"] = $adldap->user()->info($username);
$redir = "Location: https://" . $_SERVER['HTTP_HOST'] .
dirname($_SERVER['PHP_SELF']) . "/menu.php";
header($redir);
exit;
}
}
$failed = 1;
}
为什么会出现此错误:unable to bind to the AD
?
我发现了这个问题。
很明显,SELinux阻塞了我需要连接的端口,所以我基本上只是告诉SELinux可以连接到那个端口。现在一切都很顺利。以下是我允许Apache访问端口的方式:
grep httpd /var/log/audit/audit.log | audit2allow -M mypol
semodule -i mypol.pp