Fix Class ‘DOMDocument’ not found in VVV

Like most people, I hate it when things don’t ‘just work’ – even more so, when it prevents me from doing my actual work. I had this problem today when I was trying to run unit tests with PHPUnit for my WordPress plugin on Varying Vagrant Vagrants (VVV). The error was terse and unhelpful

Class 'DOMDocument' not found

Searching the web for the error isn’t too helpful. There are a lot of potential causes. Weirdly, this error wasn’t occurring in my MAMP setup. It turns out the vagrant setup was missing a PHP XML extension that gets listed as ‘DOM’ in phpinfo(). The solution was 2 commands:

sudo apt-get update
sudo apt-get install php-xml

The first command ensures you have the latest libraries. The second actually installs the PHP extension. When you re-run phpinfo(), you’ll now see it installed. Re-running phpunit successfully executes the tests without the error.

Sorry, but comments are closed. I hope you enjoyed the article