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).


$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;
file_put_contents('', $input);

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

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


Graphviz documentation