1

I am trying to set up a bare-bones implementation of GraphAware's Neo4j PHP Client, following the ReadMe. I am working on PHP 7.0.8-0ubuntu0.16.04.2 (cli) ( NTS )

To get this to work, I find that I must use sudo with Composer, against the warnings given by Composer itself.


I have installed Composer, as follows (instructions)

php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
php -r "if (hash_file('SHA384', 'composer-setup.php') === 'e115a8dc7871f15d853148a7fbac7da27d6c0030b848d9b3dc09e2a0388afed865e6a3d6b3c0fad45c48e2b5fc1196ae') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"
sudo php composer-setup.php

This led to the following announcement of success:

Composer successfully installed to: /home/blackslate/composer.phar

I then moved Composer so that it is available globally, as described here:

sudo mv /home/blackslate/composer.phar /usr/local/bin/composer

Next, I installed the latest neo4j-php-client:

sudo apt-get install php-bcmath
sudo composer require graphaware/neo4j-bolt
composer require graphaware/neo4j-php-client:^4.0

The Installation and basic usage instructions do not include the first two steps above, but the final command fails without them.

The second line showed a warning not to run Composer as root, but if I did not, then I got the following error:

Installation failed, reverting ./composer.json to its original content.


[ErrorException]                                                             
file_put_contents(/home/blackslate/vendor/composer/installed.json): failed   
to open stream: Permission denied   

This installed a directory named vendor in my home directory. I moved it to my project directory.


Finally, in my project folder, I created a file named index.php with the following script:

<?php

require_once 'vendor/autoload.php';

use GraphAware\Neo4j\Client\ClientBuilder;

$client = ClientBuilder::create()
    ->addConnection('default', 'http://neo4j:password@localhost:7474') // Example for HTTP connection configuration (port is optional)
    ->addConnection('bolt', 'bolt://neo4j:password@localhost:7687') // Example for BOLT connection configuration (port is optional)
    ->build();

I now have a directory with the following structure:

index.php            // as shown above
vendor/              // the directory installed by Composer
       autoload.php
       composer/
       graphaware/
       guzzlehttp/
       myclabs/
       psr/
       symfony/

All appears to work as expected.

My question is: is there a way I could have achieved this without using sudo to run Composer?

James Newton
  • 6,623
  • 8
  • 49
  • 113

1 Answers1

1

You shouldn't use sudo indeed. Secondly you should require the client in your project folder, not just in your home directory.

There is no need to require bolt as it is an implicit dependency of the client itself.

For the bcmath extension, it is mentioned in the README as mandatory extension to be installed.

Christophe Willemsen
  • 19,399
  • 2
  • 29
  • 36
  • So if I don't use sudo, how do I get the installation to succeed? – James Newton Sep 30 '16 at 22:08
  • 1
    @JamesNewton By running `composer require` with sudo the first time, composer created files (namely `composer.json`, `composer.lock`, and possibly the `vendors` dir) with permissions such that the second `composer require` without sudo couldn't write to them. If you had run the initial `composer require` in your project directory without sudo, you wouldn't have run into problems. You could have also changed the ownership/permissions on those sudo-created files so your base user could access them. – Mark H. Sep 30 '16 at 22:37