Page 4 of 4

PHP Virtualization: Using Virtual box and Vagrant to run Graph Kit for PHP

In this second of our three-part series on the Graph Kit for PHP (see Part 1), we’ll discuss how to virtualize your Graph Kit development environment using Vagrant, VirtualBox, and Ansible.

Virtual Development Environments FTW

A virtual development environment is one which lives on your computer while being completely isolated from your computer. The benefits are many, my favorite being the ability to test new programming software, applications, frameworks, and ideas without having to update, reconfigure, or otherwise modify the development environment on my computer.

The virtualized environment we’ll be looking at today uses VirtualBox to run a guest operating system (Ubuntu 14.04 64-bit), Vagrant to create and destroy the environment, and Ansible to provision, or install and configure, the environment. What that means for you is that you can have a fully functional development installation of the Graph Kit for PHP as easily as typing a single command into your terminal.

Installing the Tools

Installing VirtualBox and Vagrant is as simple as a quick download and installation. Grab the appropriate Vagrant installer and VirtualBox installer for your operating system, install them, and move on to the next step.

There are a few more options for Ansible, but installation remains pretty straightforward. I develop on a Mac and I’m a big fan of homebrew, so I jumped into my terminal and ran brew install ansible. If you’re on a *nix variant, you’ll be able to find Ansible in your package manager or, if you prefer, you can install the latest version via pip.

Windows users: You won’t be installing Ansible at all. Since Ansible can’t be installed on Windows, you’d normally be out of luck. Since we used phansible to build the VM, and since they have a nifty workaround for Windows users, you’re good to go after installing Vagrant and VirtualBox.

Installing the Graph Kit

Obtaining the latest version of the Graph Kit source code is as easy as (pick one):

  • Download the latest release from GitHub
  • Clone the project using git: git clone git@github.com:GraphStory/graph-kit-php.git
  • Using Composer:
    php composer.phar create-project graphstory/graph-kit-php graph-kit-php
  • Add 192.168.34.101 graph-kit-php.dev to your hosts file (Linux/MacWindows)

TIP: If you haven’t yet, you might want to install git as well. It will make installation of and updating the Graph Kit to newer versions much simpler. As a bonus, using a version control system is a development best practice, so two birds with one stone and all that.

Connection Settings

In order to connect to your Graph Story graph database instance, you’ll need to have your database connection settings and credentials. You can find these in the Graphs section in your account in the Graph Story Console.

Once you get them, they’ll go in a file named /path/to/graph-kit-php/config/secret.php. The file contents look like the following (with your connection info included, of course):

<?php

return array(
    'graphStory' => array(
        'restUsername' => 'user',
        'restPassword' => 'password',
        'restHost' => 'https://your-graph.do-stories.graphstory.com:7473',
        'restPort' => 7473,
        'https' => false,
    ),
);

Running the VM

Open your terminal, cd into the directory where you’ve installed the Graph Kit (Mine is in /Users/jeremykendall/dev/graph-story/graph-kit-php), and run the following:

vagrant up

That’s all there is to it – PHP Virtualization completed! You’ve got a virtual development environment set up, and the Graph Kit for PHP is ready to go! Visit http://graph-kit-php.dev in your browser and get started!

The first time you run vagrant up you’ll wait a few minutes for the Vagrant box to import and for Ansible to provision your environment. All subsequent runs of vagrant up will usually run in about 30 seconds.

Virtual Workflow

Here are a few handy commands to use when you’re working with a Vagrant virtual environment.  All of these commands should be run from the terminal in your graph-kit-php directory.

vagrant status: Reports on the current status of the virtual machine.

vagrant up: This is the command you’ll use to start your virtual environment. The first time it runs it will provision the virtual machine. All subsequent runs will only start the VM but won’t do any provisioning.

vagrant ssh: Use this command to ssh into your virtual machine.

vagrant halt: This command halts the VM. Think of it as shutting down your computer, but for your virtual environment.

vagrant destroy: This will halt and destroy the VM, removing all of the VM’s files. Do this when you’re done with a VM or when you’d like to blow everything away and start fresh.

Interacting with the Graph Kit Source

Just because the Graph Kit source code is on a VM doesn’t mean it’s complicated to work with. Through the magic of Vagrant synced folders, the Graph Kit installation directory is shared with the Virtual Machine. Simply point your IDE of choice to the directory where you installed the Graph Kit and dig right in.

Screenshot 2014-10-20 11.51.07

Any changes you make in the source code on your computer are reflected in the VM. This allows for the best of both worlds – using all of your everyday tools for programming while isolating your development environment.

All Done!

You’re up and running with a VM packed full of graph goodness, and it’s isolated, portable, and reproducible. Not only is this a great way to work with the Graph Kit, but it’s a great development best practice as well. As you begin to write your own applications on the Graph Story platform, you might consider doing so in a virtualized environment.

If you have any problems with these instructions, or if you have any questions about the Graph Kit, please hit us up at support@graphstory.com. We look forward to hearing from you!

 

Announcing the Graph Kit for PHP

Graph Databases

Graph databases are amazing. They have no peer when it comes to dealing with connected data. Their speed, ease-of-use, and utility make them a truly disruptive technology.

That’s all well and good, but how to get started with graphs? What is graph data, and what are graph databases? What are the practical applications of graph databases, and where in the world can one find the time to learn, implement, and integrate this new technology?

Introducing the Graph Kit for PHP

The Graph Kit for PHP is a demo app provided by Graph Story to jump start your learning, understanding, and implementation of graphs and graph databases. You’ll learn about Neo4j, nodes, relationships, Cypher (the declarative Neo4J query language), and Neo4j’s REST API. You’ll see the neo4jPHP  wrapper in action, learn best practices for working with Neo4j in PHP, and learn a few general PHP best practices while you’re at it.

Installing the Graph Kit Application

One of the most challenging parts of starting with any project is getting it up and running for the first time. In this first of a three-part series of blog posts, we’ll walk through getting set up in your existing local development environment. In Part 2, we’ll use a VM to run the Graph Kit in its own environment. In the final installment, we’ll discuss how to deploy the Graph Kit to a production environment.

Graph Kit Sample Data

What good would a graph database application be without some data? The Graph Kit sample data and a hosted instance of Neo4j is available with a free trial account on the Graph Story platform. Importing the Graph Kit data is as simple as clicking a button in your Graph Story account. Head over to Graph Story and create your account. We’ll be here when you get back.

Tools

In order to install the Graph Kit’s dependencies, you’ll need to install Composer. Complete instructions are available in Composer’s Getting Started documentation, but the short and sweet version is included here.

On *nix systems, simply run:

curl -sS https://getcomposer.org/installer | php

In order to install Composer globally, you can additionally:

mv composer.phar /usr/local/bin/composer

Note that you may need to use sudo if you run into permission problems.

On Mac systems, you can use Homebrew to install Composer like so:

$ brew update
$ brew tap homebrew/dupes
$ brew tap homebrew/php
$ brew install composer

For Windows users, an installer is available.

Connection Settings

In order to connect to your Graph Story graph database instance, you’ll need to have your database connection settings and credentials. You can find these in the Graphs section in your account in the Graph Story Console.

Once you get them, they’ll go in a file named /path/to/graph-kit-php/config/secret.php. The file contents look like the following (with your connection info included, of course):

 array(
        'restUsername' => 'user',
        'restPassword' => 'password',
        'restHost' => 'https://your-graph.do-stories.graphstory.com:7473',
        'restPort' => 7473,
        'https' => false,
    ),
);

 Application Source Code

Obtaining the latest version of the source code is as easy as (pick one):

  • Download the latest release from GitHub
  • Clone the project using git: git clone git@github.com:GraphStory/graph-kit-php.git
  • Using Composer:
    php composer.phar create-project graphstory/graph-kit-php graph-kit-php

TIP: If you haven’t yet, you might want to install git as well. It will make installation of and updating the Graph Kit to newer versions much simpler. As a bonus, using a version control system is a development best practice, so two birds with one stone and all that.

Setting Up Your Local Dev Environment

  • At the command line, cd into the directory where you installed the Graph Kit source code: cd /path/to/graph-kit-php
  • Run composer install to install the Graph Kit dependencies
  • Create a virtual host for the Graph Kit (detailed instructions below)
  • Add 127.0.0.1 graph-kit-php.dev to your hosts file (Linux/Mac, Windows)
  • Visit http://graph-kit-php.dev in your browser
  • Start learning!

Creating Virtual Hosts

The following instructions show how to configure virtual hosts for serving the
Graph Kit in a local development environment. While the file names and
restart commands are specific to the Ubuntu distribution of Linux, configuration will be
very similar on the operating system of your choice. If you have any trouble
with this section, please shoot us an email at support@graphstory.com
and we’ll help you sort it out as quickly as possible.

nginx (with PHP-FPM)

Replace the contents of the default nginx vhost (/etc/nginx/sites-available/default
on Ubuntu) with the following:

server {
    listen      80;
    server_name graph-kit-php.dev;
    root        /path/to/graph-kit-php/public;

    try_files $uri /index.php;

    location /index.php {
        fastcgi_connect_timeout 10s;
        fastcgi_read_timeout 10s;
        fastcgi_pass unix:/var/run/php5-fpm.sock;
        include fastcgi_params;
    }
}

IMPORTANT: Replace /path/to/graph-kit-php/public with the full path to your graph-kit-php directory.

Save and close the default config, and then restart nginx: sudo service nginx restart

Apache

Replace the contents of the default Apache vhost (/etc/apache2/sites-available/000-default.conf [or default.conf] on Ubuntu) with the following:

    DocumentRoot "/path/to/graph-kit-php/public"
    ServerName graph-kit-php.dev

    <Directory "/path/to/graph-kit-php/public">
        AllowOverride All
        Order allow,deny
        Allow from all
    

IMPORTANT: Replace /path/to/graph-kit-php/public with the full path to your
graph-kit-php directory.

  • Save and close the default config
  • Enable mod_rewrite for URL rewriting: sudo a2enmod rewrite
  • Restart Apache: sudo service apache2 restart

That’s It!

Congrats! You’ve completed installation and configuration of the Graph Kit for PHP,
and you’re ready to jump-start your graph database experience.

If you have any problems with these instructions, or if you have any
questions about the Graph Kit, please hit us up at support@graphstory.com.
We look forward to hearing from you!

Neo4J: Graph Databases Were Already Here

If you read an article/post/comment in the past few months that said something like, “Graphs are coming!“, then at least one thing was wrong with it:  Graphs are already here.

If you haven’t heard of graph databases, then take a look at your future.  Go ahead, we’ll be right here when you’re done.

Graph databases can analyze connected data faster than relational databases, which is the most popular database type in use today.  However, as Emil Eifrem, Ian Robinson and Jim Webber point out in Graph Databases, it’s ironic that they are called relational databases, because they’re not very good at relationships.  What’s even better is that graphs can still provide:

1. ACIDity
2. Flexibility
3. Accessibility

ACIDity is critical for all data management tools. Flexibility is critical for any business to grow where needed; If you cannot change when needs demand, then you’re gonna have a bad time.

Accessibility is critical for developers and is arguably the most important of the three. Neo4j, the most popular and full featured of the current graph database offerings, is extremely accessible to developers.

Neo4j has wide language support, its native query language, Cypher, is easy to learn, and its RESTful endpoints make integrating Neo4j into your current projects a breeze. It doesn’t matter if you favor Swift, PHP, Python, Ruby, C#/.NET, or Java.  It’s Cypher + YOUR language. You can almost forget the ‘j’ in Neo4j.

Factor in that Accenture, Adobe, Autodesk, Cisco, Deutsche Telekom, eBay, HP, T-Mobile, and Wal-Mart are all using graphs, and you have big names establishing that graph databases are not just reliable, but they’re here to stay.

Emil Eifrem, the CEO of Neo Technology, believes that by the end of this decade graph databases will be everywhere there’s software. We here at Graph Story believe that graph database adoption is growing even faster than Emil projected. Graph databases are enabling tech to move faster, and Emil & Co are making it easier and faster everyday.  Graphs are everywhere.

 

Page 4 of 4

Powered by WordPress & Theme by Anders Norén