Install DOM Extension on CentOS

This section provides a tutorial example on how to install PHP DOM Extension on CentOS systems.

On some Linux systems, you may need to install PHP DOM Extension explicitly. Here is what I did on my CentOS computer.

1. Try an PHP script that uses the DOM Extension. You see the "Class 'DOMDocument' not found" error.

herong$ php Create-HTML-DOM-Document.php output.html

PHP Fatal error:  Uncaught Error: Class 'DOMDocument' not found
  in /home/herong/Create-HTML-DOM-Document.php:7

2. Search for the DOM Extension binary package using "xml" as the keyword, not "dom", not "html".

herong$ dnf search php | grep xml

php-xml.x86_64 : A module for PHP applications which use XML
...

3. Install the DOM Extension binary package.

herong$ sudo dnf install php-xml

Installed:
  php-xml-7.2.24-1.module_el8.2.0+313+b04d0a66.x86_64

4. Try the PHP script again. It should work now.

herong$ php Create-HTML-DOM-Document.php hello.html

herong$ more hello.html
<html><body bgcolor="#ddddff"><p>Hello World!</p></body></html>

Table of Contents

 About This Book

 Introduction and Installation of PHP

 Managing PHP Engine and Modules on macOS

 Managing PHP Engine and Modules on CentOS

 cURL Module - Client for URL

DOM Module - Parsing HTML Documents

 DOM (Document Object Model) Module

 Parse and Traverse HTML Documents

 Build New HTML Documents

 Load HTML Documents with LIBXML_NOBLANKS

 Remove Whitespaces in HTML Documents

 DOCTYPE Element in HTML Documents

 Remove Dummy Elements in HTML Documents

Install DOM Extension on CentOS

 GD Module - Manipulating Images and Pictures

 MySQLi Module - Accessing MySQL Server

 OpenSSL Module - Cryptography and SSL/TLS Toolkit

 PCRE Module - Perl Compatible Regular Expressions

 SOAP Module - Creating and Calling Web Services

 SOAP Module - Server Functions and Examples

 Zip Module - Managing ZIP Archive Files

 References

 Full Version in PDF/EPUB