303

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.

3
  • 3
    This answer (enable php-xml) seems coherent, why doubt it instead of just testing it? From a few google searches it seems to be one of the possible issues
    – koopajah
    Jan 18, 2013 at 8:52
  • 1
    i just scare when i try "yum install php-xml", it will disturb my magento site..
    – ws_123
    Jan 18, 2013 at 8:58
  • DomDocument instead of DOMDocument can sometimes fix this issue .
    – jirarium
    Dec 16, 2018 at 22:56

19 Answers 19

420

You need to install the DOM extension. You can do so on Debian / Ubuntu using:

sudo apt-get install php-dom

And on Centos / Fedora / Red Hat:

yum install php-xml

If you get conflicts between PHP packages, you could try to see if the specific PHP version package exists instead: e.g. php53-xml if your system runs PHP5.3.

13
  • 40
    installing php-xml solved this for me but don't forget the 'service httpd restart'
    – zzapper
    Oct 29, 2013 at 15:36
  • 4
    @zzapper thanks, that got me on the rails! In my case I needed to restart apache2 service apache2 restart.
    – Shautieh
    Oct 28, 2016 at 16:57
  • 4
    remember to restart apache afterwards
    – Jahmic
    Oct 29, 2016 at 6:16
  • 6
    For PHP7, it's just php-doc. May 3, 2017 at 18:14
  • 15
    For me: sudo apt-get install php7.1-xml Aug 1, 2017 at 19:33
234

PHP 8.2

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

PHP 8.1

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

PHP 8.0

  • Ubuntu: apt-get install php8.0-xml
  • CentOS 8 [with php:remi-8.0 enabled]: dnf install php-xml
7
  • 15
    remember to restart apache afterwards
    – Jahmic
    Oct 29, 2016 at 6:16
  • I'm running PHP 7 (7.0.15-1~dotdeb+8.1) on an Nginx VS (via Docker) and this worked like a charm! Don't forget to do `docker-compose restart'!
    – StephanieQ
    Feb 24, 2017 at 14:50
  • 1
    PHP 7.2, CentOS yum install php72w-xml and then restart service
    – Silvan
    Aug 16, 2018 at 15:15
  • 1
    Is there not a php-xml alias/virtual package?
    – binki
    Oct 8, 2018 at 18:26
  • This is also starting to occur with php7.3 to 7.4 transition. When the web server PHP module is based on 7.3 and php-xml is 7.4. Updating to a consistent PHP version (either one) works fine. Feb 29, 2020 at 6:24
30

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.

10
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
7

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
1
  • 3
    Thanks, restarting the server worked! I had to do service apache2 restart on ubuntu. Feb 11, 2017 at 15:50
7

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!
4

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.

4
  • i found --disable-dom in Configure Command, what should i do next?
    – ws_123
    Jan 18, 2013 at 9:38
  • That depends on your system. Worst case you have to recompile PHP from scratch.
    – deceze
    Jan 18, 2013 at 9:46
  • Relying on configure option is most often a mistake, read blog.remirepo.net/post/2010/09/29/phpinfo-BUG-or-PEBKAC so it have been removed from phpinfo output in some distrobution (debian, fedora...) Feb 20, 2016 at 9:48
  • 1
    If compiled from source, you could use --enable-dom
    – DidThis
    Nov 7, 2017 at 11:51
4

In my case the problem was it was the use of namespace at the top of php file, exemple :

namespace MediaWiki\Extensions\ParserFunctions;

To solve this problem add the following line:

use DOMDocument;

So no need of installing dom or xml if they are already installed. It is a php language trap.

3

This help for me (Ubuntu Linux) PHP 5.6.3

sudo apt-get install php5.6-dom

Thats work for me.

2

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.

2

On a Amazon Linux 2 with PHP 8.0, I had to

yum-config-manager --enable remi-php80
yum install php-xml

Do not forget to restart PHP

systemctl restart php-fpm
1

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
1

On fedora 26:

dnf install php-dom

Fixes it !

1

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

1

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
1

For Centos 7 and php 7.1:

yum install php71w-xml
apachectl restart
0

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

0

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

1
0

this is the lastest for php v 8.0

sudo apt-get install php8.0-xml

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.