How to Fix “Unable to find `dot` command of GraphViz” Error in Ubuntu 12.04 for phpDocumentor


2 views

When working with phpDocumentor's graphing capabilities, you'll encounter this error if your system lacks proper GraphViz installation. The dot command is part of GraphViz's suite of tools for generating diagrams from textual descriptions.

For Ubuntu 12.04 (Precise Pangolin), you'll need both the GraphViz package and PHP bindings:

sudo apt-get install graphviz
sudo apt-get install php5-graphviz

After installation, verify GraphViz is in your PATH:

which dot
# Should return something like: /usr/bin/dot

dot -V
# Should display version information

While your include_path modification was a good thought, this error isn't related to PHP's include path. The issue is system-level - phpDocumentor needs to execute the dot binary, not include PHP files.

If standard installation doesn't work, try these approaches:

# Manual symlink if dot isn't in standard path
sudo ln -s /usr/local/bin/dot /usr/bin/dot

# For custom installations, specify the path:
phpdoc --target ./docs --directory ./src --dot /path/to/dot

Check these common pitfalls:

  • User permissions for executing dot
  • PATH environment variable in your shell
  • Apache's PATH if running via web server

Here's a fully working example after proper installation:

phpdoc -f src/MyClass.php -t docs/ --title "API Documentation" \
  --template="responsive-twig" --visibility="public,protected"

This should now process your documentation including all graph generation without the GraphViz error.


When running phpDocumentor to generate documentation with class diagrams, you encounter the error:

Unable to find the dot command of the GraphViz package. Is GraphViz correctly installed and present in your path?

This error occurs because phpDocumentor relies on GraphViz (specifically its dot executable) to generate class diagrams, but the system cannot locate this binary. There are several layers to this problem:

  1. The GraphViz package must be installed at system level
  2. The dot executable must be in your system PATH
  3. PHP must have permissions to execute it

First, install GraphViz through apt:

sudo apt-get update
sudo apt-get install graphviz

Verify the installation by checking the dot executable:

which dot
# Should return something like: /usr/bin/dot

If you don't see output from which dot, you'll need to manually add it to your PATH. First locate the binary:

sudo find / -name dot 2>/dev/null

Then add it to your PATH in ~/.bashrc or ~/.zshrc:

export PATH=$PATH:/path/to/dot/directory

For phpDocumentor to work properly, you'll also want to ensure PEAR and its dependencies are correctly set up:

sudo pear channel-update pear.php.net
sudo pear upgrade-all
sudo pear install phpdoc/phpDocumentor

Create a simple test class to verify diagram generation:

<?php
/**
* @package Test
*/
class SimpleClass {
    /**
    * @var string Test property
    */
    public $testProp;
    
    /**
    * Test method
    * @return void
    */
    public function testMethod() {}
}

Then generate documentation:

phpdoc -f TestClass.php -t ./docs --template="clean"

If problems continue, check:

# Verify the phpdoc command sees GraphViz
phpdoc --parse
# Check environment variables
printenv PATH
# Test direct dot execution
/usr/bin/dot -V

You may need to adjust PHP's open_basedir or safe_mode_exec_dir settings if they're restricting access to the dot binary.

If system-wide installation isn't possible, consider:

# Local installation in project directory
mkdir -p vendor/bin
wget https://graphviz.gitlab.io/pub/graphviz/stable/ubuntu/.../graphviz.deb
dpkg -x graphviz.deb vendor/
export PATH=$PATH:$(pwd)/vendor/usr/bin