0

我刚刚在 Windows 中安装了 neo4j 服务器并尝试连接 php。我运行了 xampp,使用 composer 安装了 neo4jphp,然后尝试使用以下脚本检查连接:

<?php
    require('vendor/autoload.php');


    $client = new Everyman\Neo4j\Client('localhost', 7474);
    print_r($client->getServerInfo());
?>

现在,不是显示服务器状态,而是发生了一个致命错误,如下所示:

致命错误:未捕获的异常“Everyman\Neo4j\Exception”,消息“无法检索服务器信息 [401]:标头:数组([日期] => 2015 年 5 月 27 日星期三 10:54:01 GMT [内容类型] = > application/json; charset=UTF-8 [WWW-Authenticate] => None [Content-Length] => 144 [Server] => Jetty(9.2.z-SNAPSHOT) ) 正文: Array ([errors] => Array ( [0] => 数组 ( [message] => 未提供授权标头。[code] => Neo.ClientError.Security.AuthorizationFailed ) ) ' 在 C:\xampp\htdocs\neo4j\vendor\everyman\neo4jphp\ lib\Everyman\Neo4j\Command.php:116 堆栈跟踪:#0 C:\xampp\htdocs\neo4j\vendor\everyman\neo4jphp\lib\Everyman\Neo4j\Command\GetServerInfo.php(53): Everyman\Neo4j\ Command->throwException('Unable to retri...', 401, Array, Array) #1 C:\xampp\htdocs\neo4j\vendor\everyman\neo4jphp\lib\Everyman\Neo4j\Command.php(69): Everyman\Neo4j\Command\GetServerInfo->handleResult(401, Array, Array) #2 C:\xa in C:\xampp\htdocs\neo4j\vendor\everyman\neo4jphp\lib\Everyman\Neo4j\Command.php 在第 116 行

如何解决这个问题?任何帮助将不胜感激。提前致谢。

4

2 回答 2

0

如果您安装了最新版本的 Neo4j,则需要授权(提供用户名和密码)才能连接到 Neo4j。您的 Everyman 捆绑包似乎没有,或者您使用的是较旧的捆绑包。我自己使用的是Neoxygen/neoclient,它确实提供了提供用户名和密码的能力。

于 2015-07-22T07:58:13.733 回答
0

它会起作用的。您只需要定义授权凭据,例如:

<?php
   require('vendor/autoload.php');

   $client = new Everyman\Neo4j\Client(
            (new Everyman\Neo4j\Transport\Curl('localhost',7474))
                ->setAuth('neo4j','neo4j')
   );

   print_r($client->getServerInfo());

相应地调整用户/密码('neo4j'/'neo4j' 是默认的)。

另一种解决方案是在访问 Neo4j 时禁用授权要求。这可以通过编辑 Neo4j 配置文件来完成:

conf/neo4j-server.properties

并将以下标志设置为 false:

dbms.security.auth_enabled=false

当然,您需要记住之后重新启动服务器。

于 2015-09-21T11:05:35.210 回答