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?