0

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.

Community
  • 1
  • 1
Juha M
  • 380
  • 3
  • 13
  • I have found no examples how credentials should be given, normally they are not expressed. The documents in http://jadell.github.io/neo4jphp/docs/index.html tell that there is a function Transport.setAuth($user, $passwd), but it is not good idea to hard code these. Is there any other ways to set the credentials in for example php.ini? – Juha M Feb 12 '15 at 19:51
  • I tried to use the setAuth method, but it fails: "Cannot instantiate abstract class Everyman\\Neo4j\\Transport". I wrote ` $client = new Client(new Transport('10.50.8.204', 8080).setAuth('admin', $mypasswd));` – Juha M Feb 13 '15 at 02:27
  • You don't need to instantiate a new Transport. The `setAuth` method is called on the $client. You are correct that you should never hardcode security credentials into an application. You can store the username/password anywhere you normally store credentials to read into your application securely: config files, Apache environment vars, etc. – Josh Adell Feb 13 '15 at 14:29

1 Answers1

1

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();
Josh Adell
  • 1,555
  • 8
  • 12