简体   繁体   English

在Apache上使用PHP绑定到Active Directory时出现问题

[英]Issues binding to Active Directory using PHP on Apache

I have a PHP script on an apache server, and every time I try to run it, it tells me: 我在apache服务器上有一个PHP脚本,每次尝试运行它时,它都会告诉我:

unable to bind to the AD

It connects fine though. 它连接正常。 I took it off the apache server, and ran it locally from my machine, and it was able to bind just fine. 我将其从apache服务器上取下来,并从我的机器上本地运行,它能够很好地进行绑定。 I'm assuming that there is something wrong with my configuration of apache. 我假设我的apache配置有问题。

I'm using the adLDAP API, and this is the following script I'm trying to run. 我正在使用adLDAP API,这是我尝试运行的以下脚本。 It's basically a test to see whether I'm able to bind successfully or not and check to see if the credentials entered are in the Active Directory. 基本上,这是一项测试,确定我是否能够成功绑定并检查输入的凭据是否在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;
}

Why am I getting this error: unable to bind to the AD ? 为什么会出现此错误: unable to bind to the AD

I figured out the issue. 我发现了问题。

Apparently SELinux was blocking the port I needed to connect to, so I just essentially told SELinux that it's ok to connect to that port. 显然SELinux阻塞了我需要连接的端口,因此我基本上只是告诉SELinux可以连接到该端口。 Now everything works like a charm. 现在,一切都像魅力。 Here is how I allowed Apache access to the port: 这是我允许Apache访问端口的方式:

grep httpd /var/log/audit/audit.log | audit2allow -M mypol
semodule -i mypol.pp

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM