Juha M
Juha M

Reputation: 500

Connecting Neo4j server with Neo4jPHP gives 401

We are just installing our first Neo4j 2.1 application to Jelastic server environment and can't get connection to db working. The simple program (from an answer in neo4jphp: Cannot instantiate abstract class Everyman\Neo4j\Transport) is this:

require('vendor/autoload.php');

use Everyman\Neo4j\Client;
$client = new Client($Server_ip_address, 8080);
print_r($client->getServerInfo()); 

The last row gives an error 401 Unauthorized:

'Unable to retrieve server info [401]:\nHeaders: Array
(
[WWW-Authenticate] => Basic realm="neo4j graphdb"
[Content-Type] => text/html; charset=ISO-8859-1
[Cache-Control] => must-revalidate,no-cache,no-store
[Content-Length] => 0
[Server] => Jetty(9.0.5.v20130815)
)
Body: Array
(
)
'.

Should I configure the user_id/password somewhere in my Apache 2.2 environment, or is there something else missing?

Thanks after all! The working version is this:

require('vendor/autoload.php');   
use Everyman\Neo4j\Client;
$client = new Everyman\Neo4j\Client($host, $port);
$client->getTransport()
  ->setAuth($username, $password);
print_r($client->getServerInfo());

Also "->useHttps()" should be used, if you don't have a trusted environment.

Upvotes: 0

Views: 763

Answers (1)

Josh Adell
Josh Adell

Reputation: 1555

If you are using authentication, you need to pass along the username/password, as shown in the example at https://github.com/jadell/neo4jphp/wiki/Getting-started#testing-your-connection

require('vendor/autoload.php');

use Everyman\Neo4j\Client;
$client = new Client($Server_ip_address, 8080);
$client->setAuth($username, $password);
print_r($client->getServerInfo());

Additionally, if you are using HTTPS (recommended if you are using authentication) you should also do:

$client->useHttps();

Upvotes: 1

Related Questions