

前の記事で「composerを使わないでneo4jphpからNeo4jに接続してみた」って書いたのは、すでにcomposerを使った記事が日本語でどっかにあったから。
さて、自分もやろうと思ったら見つからなくなったのでメモっておこう。
【手順】
1)自分のプログラムをインストールしたディレクトリに移動
2)composer.pharをダウンロード
3)neo4jphp用のcomposer.jsonの作成
4)neo4jphpのインストール
5)利用例
【解説】
1)省略
2)composer.phpのダウンロード
1 |
curl -sS https://getcomposer.org/installer | php |
を実行。
1 |
Composer successfully installed to: /var/www/html/composer.phar |
これが表示されたらOK
3)neo4jphp用のcomposer.jsonの作成
同じディレクトリにcomposer.jsonというファイル名で、以下を書き込んだjsonファイルを作る
1 2 3 4 5 |
{ "require": { "everyman/neo4jphp": "dev-master" } } |
4)neo4jphpのインストール
1 |
php composer.phar install |
というコマンドを叩く
1 2 3 4 5 6 |
Updating dependencies (including require-dev) - Installing everyman/neo4jphp (dev-master 6021d88) Cloning 6021d88dfa7082cefab5caf5d8834c889fd28138 Writing lock file Generating autoload files |
こんな感じの表示が出る。
5)利用例
(コメントアウトされてる部分を読んで自分に合った方法を使ってください)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
<?php require('vendor/autoload.php'); // インストール後にできたvendorディレクトリ //localhostの7474に接続する場合 //$client = new Everyman\Neo4j\Client(); //ホストとポートを指定するにはこちら //$client = new Everyman\Neo4j\Client('ホスト名かIP', 7575); //HTTPSや認証のあるNeo4jにはこちら(たぶん、こちらを使うと思う) $client = new Everyman\Neo4j\Client(); $client->getTransport() // ->useHttps() /HTTPSの場合 ->setAuth('username', 'password');// ここにユーザ名とパスワードを指定する。 // Test connection to server print_r($client->getServerInfo()); |
これで、サーバ情報が出れば良し
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
Array ( [extensions] => Array ( ) [node] => http://localhost:7474/db/data/node [node_index] => http://localhost:7474/db/data/index/node [relationship_index] => http://localhost:7474/db/data/index/relationship [extensions_info] => http://localhost:7474/db/data/ext [relationship_types] => http://localhost:7474/db/data/relationship/types [batch] => http://localhost:7474/db/data/batch [cypher] => http://localhost:7474/db/data/cypher [indexes] => http://localhost:7474/db/data/schema/index [constraints] => http://localhost:7474/db/data/schema/constraint [transaction] => http://localhost:7474/db/data/transaction [node_labels] => http://localhost:7474/db/data/labels [neo4j_version] => 2.3.1 [version] => Array ( [full] => 2.3.1 [major] => 2 [minor] => 3 [release] => 1 ) ) |
「Neo4jphpをcomposerを使ってインストールする」への3件のフィードバック
コメントは受け付けていません。