[Dompdf] PHP Fatal error: Class DOMImplementation not found

Updated on September 4, 2023

After fixing undefined function mb_internal_encoding encountered an another error “Uncaught Error: Class DOMImplementation not found“. Below is the complete error:

Error: [Fri Jun 16 11:07:04.798269 2023] [php7:error] [pid 820060] [client techglimpse.com:21132] PHP Fatal error:  Uncaught Error: Class 'DOMImplementation' not found in /var/www/html/wordpress/wp-content/plugins/pdfgenerate/dompdf/vendor/masterminds/html5/src/HTML5/Parser/DOMTreeBuilder.php:172\nStack trace:\n#0 /var/www/html/wordpress/wp-content/plugins/pdfgenerate/dompdf/vendor/masterminds/html5/src/HTML5.php(157): Masterminds\\HTML5\\Parser\\DOMTreeBuilder->__construct()\n#1 /var/www/html/wordpress/wp-content/plugins/pdfgenerate/dompdf/vendor/masterminds/html5/src/HTML5.php(89): Masterminds\\HTML5->parse()\n#2 /var/www/html/wordpress/wp-content/plugins/pdfgenerate/dompdf/vendor/dompdf/dompdf/src/Dompdf.php(478): Masterminds\\HTML5->loadHTML()\n#3 /var/www/html/wordpress/wp-content/plugins/pdfgenerate/formprocess.php(143): Dompdf\\Dompdf->loadHtml()\n#4 {main}\n  thrown in /var/www/html/wordpress/wp-content/plugins/pdfgenerate/dompdf/vendor/masterminds/html5/src/HTML5/Parser/DOMTreeBuilder.php on line 172, referer: http://test.techglmpse.com/2023/05/16/test/

How to solve Class DOMImplementation not found?

Solution: The “Class 'DOMImplementation' not found” error typically occurs when you’re trying to use Dompdf, which relies on the DOM extension for PHP, but the DOM extension is not installed or enabled on your server. To resolve this issue, you need to install and enable the DOM extension.

How to Install and Enable DOM Extension

Step 1: To install the DOM extension for PHP (php-xml), you can use a package manager depending upon your server’s operating system.

For Ubuntu/Debian:

# sudo apt-get install php-xml

For CentOS/RHEL:

# sudo yum install php-xml

Step 2: Verify the DOM extension being enabled.

For Apache/Nginx:

# ls -lrt 20-dom.ini
-rw-r--r-- 1 root root 44 Aug 1 19:38 20-dom.ini
# more 20-dom.ini
; Enable dom extension module

Step 3: Restart Web Server

For Apache:

# systemctl restart httpd

For Nginx:

#systemctl restart nginx

Step 4: Test

Create a PHP script (test.php) with the following content and execute it in CMD Line:

if (extension_loaded('dom')) {
     echo "DOM extension is installed.";
} else {
     echo "DOM extension is not installed.";
# php # php test.php
DOM extension is installed.

Once you’ve installed and enabled the php-xml extension, the DOM extension will be available in your PHP environment, and you should be able to use it without encountering errors related to missing classes like “DOMImplementation.”

Was this article helpful?

Related Articles

Leave a Comment