[php] Class 'DOMDocument' not found

I've found an error on a page in my Magento application; it always show this message error when I visit it:

Fatal error: Class 'DOMDocument' not found in /home/.../lib/Zend/Feed/Abstract.php on line 95

Can you give me a solution? I'm using magento 1.4.1.1.

This question is related to php xml magento

The answer is


After a long time suffering from it in PHPunit...

For those using namespace, which is very common with Frameworks or CMS, a good check in addition to seeing if php-xml is installed and active, is to remember to declare the DOMDocument after the namespace:

namespace YourNameSpace\YourNameSpace;

use DOMDocument; //<--- here, check this!

For Centos 7 and php 7.1:
yum install php71w-xml
apachectl restart


This help for me (Ubuntu Linux) PHP 5.6.3

sudo apt-get install php5.6-dom

Thats work for me.


this is the lastest for php v 8.0

sudo apt-get install php8.0-xml

PHP 7.X Centos 7

I got dependency issues when trying to install module with above suggestions, adding this flag:

--enablerepo=remi-php7X

Resolved dependencies.

So

sudo yum --enablerepo=remi-php7X install php-xml

Then

service httpd restart

Ref: Install PHP Modules


I'm using Centos and the followings worked for me , I run this command

yum --enablerepo remi install php-xml

And restarted the Apache with this command

sudo service httpd restart

Package php-dom is a virtual package provided by:
  php7.1-xml 7.1.3+-3+deb.sury.org~xenial+1
  php7.0-xml 7.0.17-3+deb.sury.org~xenial+1
  php5.6-xml 5.6.30-9+deb.sury.org~xenial+1
You should explicitly select one to install.

In case anyone using 5.6 versions then go with this way

sudo apt-get install php5.6-xml

For Php Ver PHP7, Ubuntu:

sudo apt-get install php7.1-xml

or by

yum install php-xml

PHP8: (latest version)

sudo apt-get install php8.0-xml

PHP7:

sudo apt-get install php7.1-xml

You can also do:

sudo apt-get install php-dom

and apt-get will show you where it is.


If compiling from source with --disable-all then DOMDocument support can be enabled with
--enable-dom

Example:

./configure --disable-all --enable-dom

Tested and working for Centos7 and PHP7


Using Suse Linux (Linux linux 3.16.7-48-default) and PHP 5.6.1 as root, this helped:

zypper in php5-dom

plus restart

systemctl restart apache2

For PHP 7.4 Install the DOM extension.

Debian / Ubuntu:

sudo apt-get update
sudo apt-get install php7.4-xml
sudo service apache2 restart

Centos / Fedora / Red Hat:

yum update
yum install php74w-xml
systemctl restart httpd

For previous PHP releases, replace with your version.


Create an empty PHP file and put only <?php phpinfo(); in it, look at it in a browser.
Check if you can spot --disable-dom in the configuration options and/or if you can see details about the DOM extension in the list below.

If you cannot see DOM in the list or you see it is disabled, your PHP installation does not include the DOM extension. You'll need to recompile your PHP installation from source to remedy that.


PHP 7.0:

  • Ubuntu: apt-get install php7.0-xml
  • CentOS / Fedora / Red Hat: yum install php70w-xml

PHP 7.1:

  • Ubuntu: apt-get install php7.1-xml
  • CentOS / Fedora / Red Hat: yum install php71w-xml

PHP 7.2:

  • Ubuntu: apt-get install php7.2-xml
  • CentOS / Fedora / Red Hat: yum install php72w-xml

PHP 7.3:

  • Ubuntu: apt-get install php7.3-xml
  • CentOS / Fedora / Red Hat: yum install php73w-xml

PHP 7.4:

  • Ubuntu: apt-get install php7.4-xml
  • CentOS / Fedora / Red Hat: yum install php74w-xml

PHP 8.0

  • Ubuntu: apt-get install php8.0-xml
  • CentOS 8 [with php:remi-8.0 enabled]: dnf install php-xml

I'm using CentOS 7 with virtualmin and three PHP versions. I also have REMI repo enabled. it worked for me:

Step 1:

Just append PHP major version number like this php{version number}-xml. And run yum install

yum install php70-php-xml
yum install php71-php-xml
yum install php72-php-xml

Step 2:

Don't forget to restart Apache:

service httpd restart

On fedora 26:

dnf install php-dom

Fixes it !


If you are using PHP7.0 to install Magento, I suggest to install all extensions by this command

sudo apt-get install php7.0 php7.0-xml php7.0-mcrypt php7.0-curl php7.0-cli php7.0-mysql php7.0-gd libapache2-mod-php7.0 php7.0-intl php7.0-soap php7.0-zip php7.0-bcmath

I need to Google some times to meet Magento requirement.

I think you can replace the PHP version to 7.x if you use another PHP version

And restart Apache is needed to load new extensions

sudo service apache2 restart


Examples related to php

I am receiving warning in Facebook Application using PHP SDK Pass PDO prepared statement to variables Parse error: syntax error, unexpected [ Preg_match backtrack error Removing "http://" from a string How do I hide the PHP explode delimiter from submitted form results? Problems with installation of Google App Engine SDK for php in OS X Laravel 4 with Sentry 2 add user to a group on Registration php & mysql query not echoing in html with tags? How do I show a message in the foreach loop?

Examples related to xml

strange error in my Animation Drawable How do I POST XML data to a webservice with Postman? PHP XML Extension: Not installed How to add a Hint in spinner in XML Generating Request/Response XML from a WSDL Manifest Merger failed with multiple errors in Android Studio How to set menu to Toolbar in Android How to add colored border on cardview? Android: ScrollView vs NestedScrollView WARNING: Exception encountered during context initialization - cancelling refresh attempt

Examples related to magento

Where are Magento's log files located? find . -type f -exec chmod 644 {} ; Get product id and product type in magento? There has been an error processing your request, Error log record number Class 'DOMDocument' not found Magento: Set LIMIT on collection How to remove index.php from URLs? Get skin path in Magento? SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '1922-1' for key 'IDX_STOCK_PRODUCT' Service Temporarily Unavailable Magento?