Learn how to solve the Symfony error "Attempted to load class "DOMDocument" from the global namespace" in Ubuntu quickly.

In most of the cases, the PHP xml extension is not included on Ubuntu, which throw an exception with the usage of classes like XmlFileLoader or parseFileToDOM or XmlUtils that instantiate the DOMDocument class.


To solve this issue execute the following command in a terminal:

sudo apt-get install php-xml

Then restart apache (in case it's active) using:

sudo service apache2 restart

and continue with what you were doing.

Still without work?

If the installation of the php-xml extension doesn't work, then proceed to install php-mbstring and php-curl using:

sudo apt-get install php-curl
sudo apt-get install php-mbstring
sudo apt-get update

This should fix the problem, happy coding !

Senior Software Engineer at Software Medico. Interested in programming since he was 14 years old, Carlos is a self-taught programmer and founder and author of most of the articles at Our Code World.