Skip to content
cPanel Guides

How to Enable the PHP DOM Extension in cPanel

Fix "Class DOMDocument not found" on cPanel hosting: turn on the PHP dom extension in Select PHP Version, use PHP Selector for your domain, and fix Laravel Artisan.

Enable the PHP DOM extension in cPanel, step by step guide

To fix the error Class "DOMDocument" not found on HostGrap cPanel hosting, turn on the PHP DOM extension yourself in cPanel. Open Select PHP Version, choose the PHP version your website uses, and tick dom in the list of extensions. If the error is still there after that, open the Per Domain Settings tab in the same tool and click Use PHP Selector next to your domain, so that the domain uses the settings you just changed. This guide shows each step with pictures, and how to check that it worked for both your website and Laravel Artisan commands.

What does the DOMDocument error mean?

DOM is a PHP extension that lets PHP read and change HTML and XML documents. The DOMDocument class comes from it. Many PHP tools need it: Laravel and many of its packages, PDF and Excel libraries, sitemap and RSS generators, HTML sanitisers and some WordPress plugins.

When the extension is off for the PHP version that runs your code, PHP stops with an error such as Class "DOMDocument" not found or Call to undefined function dom_import_simplexml(). Nothing is wrong with your code: PHP is simply missing a part that your code expects. On HostGrap cPanel hosting you can turn it on in a minute, without opening a ticket.

Step 1: Open Select PHP Version in cPanel

Log in to cPanel. In the Software section, click Select PHP Version. You can also type "php" in the search box at the top of cPanel to find it quickly. Do not confuse it with MultiPHP Manager, which is a different tool next to it.

The Software section of cPanel with Select PHP Version marked as Step 1
Step 1: open Select PHP Version in the Software section of cPanel.

Step 2: Choose your PHP version

Select PHP Version opens on the Account Global Settings tab. At the top you see Current PHP version. Choose the version your website needs, for example 8.2 for a Laravel 10 or 11 project. If it shows "native", pick a numbered version from the list, because the extensions of the native version can't be changed here.

Extensions are set for each PHP version on its own. If you tick dom while 8.4 is selected, it is on for PHP 8.4 only, not for 8.2. So make sure the version shown here is the same one your website and your commands use.

Step 3: Tick the dom extension

Below the version you see every extension, in alphabetical order. Scroll to D and tick dom. Extensions with a light grey tick, such as date, are built in and always on.

The extension list in Select PHP Version with PHP 8.2 chosen and dom ticked
Steps 2 and 3: choose your PHP version, then tick dom.

In most versions of the tool the change is saved as soon as you tick the box. If your page shows a Save button, click it. Then reload your website. For most accounts, the error is gone at this point.

Step 4: If it still fails, use PHP Selector for your domain

A domain can get its PHP from one of two tools: the PHP Selector (the Select PHP Version tool you just used) or cPanel's MultiPHP Manager. The extension you ticked only works for domains that use PHP Selector. If your domain uses MultiPHP Manager, it does not see the change, and the error stays.

To check, open the Per Domain Settings tab in Select PHP Version. The table shows each domain in your account, its PHP version and which tool handles it. Find your domain. If the Action column shows a blue Use PHP Selector button for it, click that button. The domain then uses PHP Selector and the dom extension you turned on in Step 3. Domains that show Use MultiPHP Manager already use PHP Selector, so leave them as they are.

The Per Domain Settings tab with the Use PHP Selector button marked for a domain handled by MultiPHP Manager
Step 4: click Use PHP Selector next to your domain.

After the switch, check the PHP version shown for the domain. If it is not the version you set up in Step 2, choose the right one in Account Global Settings and make sure dom is ticked for it.

Laravel Artisan and other command line tools

Artisan, Composer and cron jobs run PHP from the command line, not through your website, so they use whichever PHP program you call. On HostGrap cPanel servers each PHP version has its own program, for example /opt/alt/php82/usr/bin/php for PHP 8.2. The extensions you tick in Select PHP Version for a version are used by that version's program as well, so turning on dom for 8.2 fixes php artisan too, as long as you call the 8.2 program.

To check, open Terminal in cPanel (or connect with SSH) and run:

/opt/alt/php82/usr/bin/php -m | grep -i dom

If the answer is dom, the extension is on for PHP 8.2 on the command line. Then run Artisan with the same program, for example:

cd ~/myapp && /opt/alt/php82/usr/bin/php artisan optimize:clear
Terminal in cPanel showing the dom check and an Artisan command run with PHP 8.2
Check the extension from Terminal, then run Artisan with the same PHP version.

Use the same full path in your cron jobs, for example /opt/alt/php82/usr/bin/php /home/username/myapp/artisan schedule:run, so that your scheduled tasks run on the same PHP version, with the same extensions, as your website. Change 82 to your version (81, 83, 84) and username and myapp to your own.

Quick checklist

WhereWhat to check
Select PHP Version, Account Global SettingsThe PHP version your site uses is selected, and dom is ticked for it
Select PHP Version, Per Domain SettingsYour domain is handled by PHP Selector (if not, click Use PHP Selector)
Terminal or SSHYour version's PHP program, run with -m, lists dom
Cron jobsThe command uses the full path of the same PHP version

Frequently asked questions

Is the DOM extension on by default?

Not always. The extensions that are on by default can differ between PHP versions and between accounts, so a project that worked on one version can fail after you change to another. Checking the list in Select PHP Version shows you exactly what is on for each version.

Do I need to ask support to enable DOM?

No. On HostGrap cPanel hosting you can turn PHP extensions on and off yourself in Select PHP Version, as shown above. If you follow every step and still see the error, message our support team and tell us your domain, the PHP version and the exact error, and we will check it for you.

Will turning on dom slow down my website?

No. The DOM extension is small and is only used when your code needs it. Turn on the extensions your software asks for and leave the rest off.

Why does my website work but php artisan still fails?

Because the website and the command line can use different PHP versions. When you type php in Terminal, the version that runs may not be the one your website uses. Call the full path of the right version, such as /opt/alt/php82/usr/bin/php artisan, and check it with -m as shown above.

Does this work on a VPS or VDS?

This guide is for cPanel hosting with Select PHP Version. On a VPS or VDS you manage the server yourself, so you install the extension with your server's package manager or control panel. For example, on Ubuntu with PHP 8.2 from the Ondřej Surý repository, the package is php8.2-xml, which includes DOM.

If you need help, message us on WhatsApp in English, Sinhala or Singlish. You can see every cPanel hosting plan here.

Share this article

More from the blog

All posts

HostGrap Now Has Its Own Network: AS217984

HostGrap Technologies now has its own ASN, AS217984. What an ASN is and what it brings you: our own IP addresses, faster local traffic in Sri Lanka, RPKI and IPv6.