I would really love to see more of my fellow PHP developers talking about, playing with, and building awesome applications on top of graph databases. They really are a powerful storage solution that fits well into a wide variety of domains.
In this two part series, I'll detail how to set up a development environment for building a project with a graph database (specifically Neo4j). Part 1 will show how to set up the development and unit testing databases. In Part 2, we'll create a basic application that talks to the database, including unit tests.
All the steps below were performed on Ubuntu 10.10 Maverick, but should be easy to translate to any other OS.
Grab the Components
There are a few libraries and software tools needed for the project. First off, we'll need to install our programming environment, specifically PHP, PHPUnit and Java. How to do this is dependent on your operating system. My setup is PHP 5.3, PHPUnit 3.6 and Sun Java 6.Next, we need to get Neo4j. Download the latest tarball from http://neo4j.org/download. I usually go with the latest milestone release (2.0 at this time.)
> cd ~/Downloads > wget http://dist.neo4j.org/neo4j-community-2.0.1-unix.tar.gz
Set Up the Development Instance
It is possible to put test and development data in the same database instance, but I prefer a two database solution, even when using a SQL database. I do this because 1) I don't have to worry about accidentally blowing away any development data I care about, and 2) I don't have to worry about queries and traversals in my unit tests accidentally pulling in development data, and vice versa.Unlike SQL or many NOSQL database servers, Neo4j cannot have more than one database in a single instance. The only way to get two databases is to run two separate instances on two separate ports or hosts. The instructions below describe how to set up our development and unit testing databases on the same host but listening on different ports.
First, create a point to hold both neo4j instances, and unpack the development instance:
> mkdir -p ~/neo4j > cd ~/neo4j > tar -xvzf ~/Downloads/neo4j-community-2.0.1-unix.tar.gz > mv neo4j-community-2.0.1 devNext, configure the server by editing the file "~/neo4j/dev/conf/neo4j-server.properties". Make sure that the server is on port 7474
org.neo4j.server.webserver.port=7474If you will be accessing the database instance from a host other than localhost, uncomment the following line:
org.neo4j.server.webserver.address=0.0.0.0Save the config and exit. Now it's time to start the instance.
> ~/neo4j/dev/bin/neo4j startYou should be able to browse to the Neo4j Browser panel: http://localhost:7474
Set Up the Testing Instance
Unpack the test instance:> cd ~/neo4j > tar -xvzf ~/Downloads/neo4j-community-2.0.1-unix.tar.gz > mv neo4j-community-2.0.1 testNext, configure the server by editing the file "~/neo4j/test/conf/neo4j-server.properties". Make sure that the server is on port 7475 (note that this is a different port from the development instance!)
org.neo4j.server.webserver.port=7475If you will be accessing the database instance from a host other than localhost, uncomment the following line:
org.neo4j.server.webserver.address=0.0.0.0We need one more change to differentiate the testing from the development instance. Edit the file "~/neo4j/test/conf/neo4j-wrapper.properties" and change the instance name line:
wrapper.name=neo4j-testSave and exit, then start the instance.
> ~/neo4j/test/bin/neo4j startYou should be able to browse to the Neo4j Browser panel: http://localhost:7475
Congratulations! Everything is set up and ready for us to build our application. In Part 2 of this series, I'll talk about setting up unit tests and building a basic application using a graph database as a backend.
Great post Josh! I like the step-by-step instructions! Would love something like that in a README or the Neo4j Manual at docs.neo4j.org/chunked/snapshot/
ReplyDelete/peter
Thanking You
ReplyDeleteYour blog is very informative
software development
Thanks for this really helpful tutorial..
ReplyDeleteGood work, Keep it UP.
Thank you!
ReplyDeleteHank
just a note, I think you have a typo following this header regarding dev vs 'test' instance:
ReplyDelete'Set Up the Testing Instance'
Unpack the development instance
Hi Josh
ReplyDeleteWhen saving a node, I got the error below, any suggestion?
Fatal error: Uncaught exception 'Everyman\Neo4j\Exception' with message
'Unable to create node [500]:
Headers: Array
(
)
Body: Array
(
[error] => Failed to connect to ::1: Permission denied [7]
)
' in phar:///opt/neo4jphp.phar/lib/Everyman/Neo4j/Command.php:116
Stack trace:
#0
phar:///opt/neo4jphp.phar/lib/Everyman/Neo4j/Command/CreateNode.php(68):
Everyman\Neo4j\Command->throwException('Unable to creat...', 500,
Array, Array)
#1 phar:///opt/neo4jphp.phar/lib/Everyman/Neo4j/Command.php(69):
Everyman\Neo4j\Command\CreateNode->handleResult(500, Array, Array)
#2 phar:///opt/neo4jphp.phar/lib/Everyman/Neo4j/Client.php(583):
Everyman\Neo4j\Command->execute()
#3 phar:///opt/neo4jphp.phar/lib/Everyman/Neo4j/Client.php(490):
Everyman\Neo4j\Client->runCommand(Object(Everyman\Neo4j\Command\CreateNode))
#4
phar:///opt/neo4jphp.phar/lib/Everyman/Neo4j/Node.php(110):
Everyman\Neo4j\Client->saveNode(Object(Everyman\Neo4j\Node))
#5 /var/www/html/1140/application/controllers/test_neo4j.php(28):
Everyman\Neo4j\Node->save()
#6 [interna in phar:///opt/neo4jphp.phar/lib/Everyman/Neo4j/Command.php
on line 116
Neil
It caused by the selinux. Turn it off and it works.
ReplyDeleteif some of your instance isn't working at first launch, simply try to re-start it again
ReplyDeleteI already address downloading the plugin, as well as changing the ports between the development and testing database. Not sure about https, since I don't use it in development environments. I'll have to check out if it affects anything and make any appropriate changes. Thanks for the suggestions!
ReplyDeletesuddenly i'm getting this error when deleting the test instance:
ReplyDeleteDELETE /db/data/cleandb/secret-key==> 500 Internal Server Error==> "Node[0]"
any ideas?
i managed to delete all nodes via cypher
ReplyDeletestart n=node(*) delete n;
and then run my script (adding some new nodes) again and the 0's re-appeared. strange
I think current versions of Neo4j are deprecating the "root" node (node 0) and future versions are removing it altogether. I will update the post to show how to use Gremlin to reset the database instead of the plugin (can't use Cypher since not all versions support deleting with Cypher.)
ReplyDeletei switched from 1.8-SNAPSHOT to 1.8 stable and it seems that only 1 instance can run via webadmin. although i can acces both of them via console and neo4j-shell, i'm unable to do so via webadmin.
ReplyDeletethe webadmin works for just the first started instance. for the second it tries to access it but never returns any data
the same problem still persists in v1.9
ReplyDeleteHi friends, i want say important thing to u all.if u are planning to study software
ReplyDeletelanguages or sotware training u must go to besant technologies where they
providing high quaity of teaching with experienced MNC working professionls.I
studied php course in Besant technologies.now i got job in MNC company.i want to
thank besant technologies. friends if want further details ,check below link.
php training in chennai
thank you
Hi friends, i want say important thing to u all.if u are planning to study software
ReplyDeletelanguages or sotware training u must go to besant technologies where they
providing high quaity of teaching with experienced MNC working professionls.I
studied php course in Besant technologies.now i got job in MNC company.i want to
thank besant technologies. friends if want further details ,check below link.
php training in chennai thank you
Thanks for sharing these niche piece of coding to our
ReplyDeleteknowledge. Here, I had a solution for my inconclusive problems & it’s
really helps me a lot keep updates…
http://phptraininginchennai.in/
It was really a wonderful article and I was really impressed by reading this blog. Thanks for sharing this informative blog. I did HTML5 Training in Chennai at FITA academy, Its really useful for me. Suppose if anyone interested to learn real time PHP Training Chennai reach FITA.
ReplyDeleteSmm panel
ReplyDeletesmm panel
İş ilanları blog
İnstagram Takipçi Satın Al
Hırdavatçı
beyazesyateknikservisi.com.tr
SERVİS
Tiktok Para Hilesi İndir
Good content. You write beautiful things.
ReplyDeletehacklink
taksi
vbet
mrbahis
sportsbet
sportsbet
vbet
korsan taksi
mrbahis
Good text Write good content success. Thank you
ReplyDeletemobil ödeme bahis
tipobet
kibris bahis siteleri
betpark
slot siteleri
kralbet
betmatik
poker siteleri
https://saglamproxy.com
ReplyDeletemetin2 proxy
proxy satın al
knight online proxy
mobil proxy satın al
6WB17C