Magento: Class 'DOMDocument' not found

Magento: Class 'DOMDocument' not found

September 19, 2026 · Illustrated author avatarBy Stefan Bogdanescu
Magento: Class 'DOMDocument' not found

Solving the “Class ‘DOMDocument’ not found” Error in Magento

Installing Magento on AWS Lightsail can be a straightforward process when done correctly. However, as you’ve encountered, missing dependencies like the DOMDocument class can lead to frustrating errors during installation.

Understanding the DOMDocument Class

The DOMDocument class is part of PHP’s DOM extension, which provides functionality for working with XML documents in a tree-based structure. This class is used extensively by Magento’s configuration system to parse and load XML files such as config.xml.

Troubleshooting the Missing Class Issue

Step 1: Verify Your PHP Installation

The error message suggests that the DOMDocument class is not found, which typically means the required extension isn’t enabled in your PHP installation. To confirm this:

  • Access your AWS Lightsail instance using SSH.
  • Run the command php --ini.
  • This will show you the location of your php.ini file.

Step 2: Enable the DOM Extension

  1. Open the php.ini file in a text editor (you can use nano or vim).

    nano /etc/php/7.2/cli/php.ini
    
  2. Look for the following line:

    ;extension=dom.so
    
  3. Remove the semicolon (;) at the beginning of the line to enable the extension.

  4. Save and close the file.

  5. Restart your PHP service for the changes to take effect:

    sudo systemctl restart php7.2-fpm
    

Step 3: Verify Your Changes

After enabling the dom.so extension, you can verify it’s active by checking your PHP info page again at http://13.239.86.161/info.php. The DOM section should now be visible.

Alternative Solutions to Consider

Using Composer for Dependency Management

If the above steps don’t resolve the issue, consider using Composer for dependency management in your Magento installation. Composer ensures that all required packages and libraries are installed correctly.

To install Magento with Composer:

  1. Navigate to your project directory (usually /var/www/html).
  2. Run composer require magento/product-community-edition --no-update.
  3. Then, run composer update.

Composer will automatically install the required dependencies, including the DOM extension if needed.

Conclusion

The “Class ‘DOMDocument’ not found” error in Magento is usually caused by a missing or incorrectly configured PHP extension. By enabling the necessary extensions and using Composer for dependency management, you can avoid such issues during installation.

Remember to always keep your system up-to-date and maintain good version control practices when working with complex frameworks like Magento.

For more detailed guides on Magento installations and troubleshooting best practices, I recommend checking out our in-depth tutorials at Laravel Company.

API Extensions Configuration Errors

Our network