Graphviz + PHP + Ubuntu Linux 14.04 via exec

As the installation of the PHP Graphviz library on Ubuntu seems quite tricky. This shows a fast (& dirty) way of using Graphviz.

sudo apt-get install graphviz

Save and execute the following PHP code in a directory with full permissions (777).

<?php

$input = <<<DATA
digraph G {
main [label="main\n(start here)"];
main -> parse -> execute;
main -> init;
main -> cleanup;
execute -> make_string;
execute -> printf
init -> make_string;
main -> printf;
execute -> compare;
}
DATA;
file_put_contents('input.dot', $input);

exec('dot -Tpng input.dot -o graph.png');

echo ('<img src="graph.png" />');

?>

References:
Graphviz documentation