【发布时间】:2016-09-30 21:39:43
【问题描述】:
我正在尝试设置 GraphAware 的 Neo4j PHP 客户端的基本实现,遵循ReadMe。我正在开发 PHP 7.0.8-0ubuntu0.16.04.2 (cli) ( NTS )
为了让它工作,我发现我必须将 sudo 与 Composer 一起使用,而不是 Composer 本身给出的警告。
我已经安装了Composer,如下(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
这导致了以下成功公告:
Composer successfully installed to: /home/blackslate/composer.phar
然后我移动了 Composer,以便它在全球范围内可用,如 here 所述:
sudo mv /home/blackslate/composer.phar /usr/local/bin/composer
接下来,我安装了最新的neo4j-php-client:
sudo apt-get install php-bcmath
sudo composer require graphaware/neo4j-bolt
composer require graphaware/neo4j-php-client:^4.0
安装和基本使用说明不包括上面的前两个步骤,但没有它们最终命令会失败。
第二行显示警告不要以 root 身份运行 Composer,但如果我没有,则会收到以下错误:
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
这在我的主目录中安装了一个名为 vendor 的目录。我把它移到了我的项目目录。
最后,在我的项目文件夹中,我使用以下脚本创建了一个名为 index.php 的文件:
<?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();
我现在有一个具有以下结构的目录:
index.php // as shown above
vendor/ // the directory installed by Composer
autoload.php
composer/
graphaware/
guzzlehttp/
myclabs/
psr/
symfony/
一切似乎都按预期工作。
我的问题是:有没有办法在不使用 sudo 运行 Composer 的情况下实现这一目标?
【问题讨论】:
标签: php neo4j composer-php sudo graphaware