I have just transferred a Drupal 7 site from my local development environment (OSX / MAMP) to a CentOS server.

It seems to work for the most part as an anonymous user, it's a fairly simple site at this point, however I can instigate the following error in 2 ways:

PHP Fatal error: Class 'DOMDocument' not found in modules/filter/filter.module on line 1041

Either by:

* Logging In (log in appears to be successful, as the error occurs on every page until I go to /user/logout , at which point the site becomes usable again)
* Submitting a Views exposed filter that returns no result (If a result is found, no error occurs)

Googling doesn't really find anything, however I did realize that my file_temporary_path wasn't set correctly, it's now set to s:4:"/tmp";

Apparently sites/default/files permission might be related as well, but that's set to 777.

Please help!

Comments

carn1x’s picture

This was fixed by installing the package php-xml

bdimaggio’s picture

...but this helped me too. Thanks, carn1x.

neethu r’s picture

Installing the package php-xml resolved it for me too.

For people using Redhat Linux, all you have to do is:

yum install php-xml and restart apache

victor.bexelius’s picture

Hi! Just wanted to say thank you for this info.

Case:
Working site moved to other VPS, drush cleared cache and error occurred. Reading logs + googling the error resulted in this fix as nr 1 hit in list.

robertloo’s picture

6 years later, this helped me too.

x7ian’s picture

7 years latter still works! Thank you!

v.kydyba’s picture

It helps me after 10 years, thanks.

For installing php-xml on php 5.6 I used a command:

apt-get install php5.6-zip php5.6-xml
purabdk’s picture

Thanks, for post, I found helpful..

zakir.gori’s picture

Those are using Ubuntu 16.04
if you install php then it will run your php 7
I have install php 5 to install drupal 7 it works but i never checked which version of php is running.
I was installing php-xml no error on installation, But did't work for me.
I was still faceing same issue "PHP Fatal error: Class 'DOMDocument' not found in modules/filter/filter.module on line 1041"

To solve do following
Purge your all php and reinstall php7 and then try install php-xml extention.
or
Switch PHP version:
From php5.6 to php7.0 :
Apache:
sudo a2dismod php5.6 ; sudo a2enmod php7.0 ; sudo service apache2 restart
CLI:
sudo ln -sfn /usr/bin/php7.0 /etc/alternatives/php
and then install php-xml extention

zakir.gori

aytee’s picture

Thanks zakir.gori. I had a similar problem on my Ubuntu 16.04. I already had php7.0 installed, so all I had to do was install the php-install (sudo apt-get install php-xml) to resolve the issue.

johnbowen’s picture

I just upgraded a server to Ubuntu 18.04, and started seeing the symptoms in this thread (Drupal sites start producing errors after signing in). PHP had been upgraded on the server in the process, so executing the above statement, modified for the move from PHP 7.0 to 7.2, fixed it. 

sudo a2dismod php7.0 ; sudo a2enmod php7.2 ; sudo service apache2 restart

jigneshkumar’s picture

If you are using ubantu 16.04 with php 5.6 then you need to use following command to install php-xml

$ sudo apt-get update 
$ sudo apt-get install php5.6-xml

then restart your apache server to see changes.

eworwa’s picture

Great! this did the trick for me.

Thank you very much.

vjsutar’s picture

$ sudo apt-get update 
$ sudo apt-get install php5.6-xml
$ sudo service apache2 restart.
Prashant.c’s picture

Thanks a lot life saving answer

$ sudo apt-get update 
$ sudo apt-get install php5.6-xml
$ sudo service apache2 restart

Prashant Chauhan
Engineer Backend

wranvaud’s picture

As a general rule, packages that used to be called php-something could have the version added to it when you upgrade.
I also had to install php5.6-mysql for it to work. Read the error messages and install what's missing. I had this issue today on ubutnu 14.04, after an update.

And I also had to restart apache, rebuild registry and clear caches to have it all working again.
Thanks for posting this!

bhatrafiq’s picture

I was trying all above stuff. but no luck. I got the same issue when i installed existing drupal 7 site on my local machine with ubuntu 16.4 and php 7.0. Once go into the Admin side of site and tried to flush the cache then i was not able to see the home page (404 not found) Then i check the error log the issue was showing like: "
PHP Fatal error: Class 'DOMDocument' not found in modules/filter/filter.module on line 1041"

Please help.

doakym’s picture

Could you solve it? i have the same error.

SivaprasadC’s picture

@doakym

By following steps it got resolved for me.

sudo apt-get install php7.0-xml;
sudo service apache2 restart;
nor sairi’s picture

its also work for me.. tqsm

jaswanttak’s picture

Sometime only apache restart doesnt help, you must restart the php-fpm service in order for the updates to work, try the below command and see..

Restart PHP FPM command: service php-fpm restart.

Cheers

ressa’s picture

Make sure to restart your server after installing PHP XML. Using the Scotch Box 3.0 with PHP 7, these two commands fixes the error Error: Class 'DOMDocument' not found in /var/www/public/core/lib/Drupal/Component/Utility/Html.php for me:

sudo apt-get install php7.0-xml;
sudo service apache2 restart;
soupman99’s picture

@ressa I did that but I still get the same error.  Any ideas?  I'm using Scotch Box 3.0 also.

ressa’s picture

I am not sure, I ended up just using PHP 5.6 ... But the issue Scotch Box 3.0 is missing php7.0-xml has many suggestions for solutions. Perhaps one of them can help you?

peterx’s picture

Drupal 8 equivalent solved the same way: Class 'DOMDocument' not found in core/lib/Drupal/Component/Utility/Html.php on line 286
Install php7.2-xml.