PHP 7 DOMDocument not found

PHP 7 DOMDocument not found

  1. Blog
  2. 15 November 2026
  3. 3 min read

Stefan Bogdanescu

Founder & Senior Architect

PHP 7 DOMDocument not found

Running php artisan cache:clear on a PHP 7 installation should be a routine maintenance task, yet encountering the error Fatal error: Class 'DOMDocument' not found indicates a missing extension rather than a code logic issue. The traceback points to /var/www/html/vendor/symfony/symfony/src/Symfony/Component/Config/Util/XmlUtils.php, where Symfony attempts to parse configuration files using the DOM library.

The root cause lies in the package manager's naming convention versus the actual runtime requirements. You are running PHP 7, but the command you executed—sudo apt-get install php5-dom—targets the legacy PHP 5 stack. Even though modern Linux distributions often symlink packages to avoid version confusion, explicitly requesting php5-dom ensures that only the older extension is loaded into your PHP configuration. Consequently, when your application initializes the DOM parser required by Symfony's XML utilities, the runtime cannot locate the class definition because it was never compiled for your current PHP interpreter version.

To resolve this, you must install the specific package corresponding to your PHP major version. If your system has installed PHP 7 via the standard Ubuntu repositories, the correct command is:

sudo apt-get install php7.0-dom

Alternatively, if you are using a different minor version of PHP or have switched from .deb packages to pecl, the package name might differ slightly (e.g., php7.1-dom). You can verify which specific PHP binary is active by running php -v. Once you identify the exact version number, append -dom to the corresponding package name in your installation command.

After installing the correct extension, you must ensure it is actually loaded. The standard Ubuntu packages usually include a configuration file at /etc/php/7.0/mods-available/dom.ini. If this file exists but does not show up in your active configuration, you may need to enable it:

sudo phpenmod dom

You can verify that the extension is now recognized by creating a temporary PHP script or running php -m in your shell. If dom appears in the output of php -m, the class definition should be available to your application immediately. In some cases, you might need to restart your web server (such as Apache or Nginx with PHP-FPM) if they are caching module states, though this is rare on modern setups where modules are loaded dynamically per request.

It is also worth noting that upgrading from Ubuntu 14.04 LTS presents specific challenges, as the official repositories for that release may no longer provide updated packages for PHP 7. If you are running a legacy environment like 14.04 with an older PHP version, you might find that the dom extension was omitted during the initial installation due to space constraints or strict repository policies. In such scenarios, rebuilding your PHP binary using PECL (pecl install dom) offers more control over which extensions are compiled against your specific PHP configuration.

If you are managing multiple Laravel applications on the same server and this issue occurs across several of them, it is highly likely that a global configuration error or an incorrect php.ini setting is preventing the extension from loading globally. Always check the output of phpinfo() to ensure the DOM module is listed without any conditional comments indicating it was disabled.

For developers maintaining older infrastructure, ensuring that all necessary extensions are explicitly installed for the correct PHP version prevents obscure runtime errors like missing core classes in Symfony components. While platforms like LaravelCompany.com offer hosting solutions with pre-configured environments, understanding these underlying system dependencies remains essential when deploying custom or self-hosted applications on raw Linux servers.

Our network