How to enable PHP DOM extension?

I just moved my WordPress website to a new server, and now I see a message that says, ‘Please enable the DOM extension in your PHP configuration.’ After some research, I found that the DOM extension needs to be enabled in my php.ini file. However, I’m unsure where to make the changes. How can I enable the DOM extension in php.ini?

By default, the DOM extension should already be enabled in PHP. You can check if the extension exists by running the command in your terminal.

php -m

If the extension is missing, it may not be installed on your server. You can install it by running the command:

sudo apt-get install php-xml

or specific version of the extension

sudo apt-get install php8.1-xml

If the extension is still not enabled, you can enable it by editing your PHP configuration file (php.ini).

  • Search for the following line in the file: “;”.
  • Remove the semicolon “;” at the beginning of the line to uncomment it,
  • Or add “” if it’s not already there.
  • Save the file and restart your web server (e.g. Apache, Nginx) and PHP.

After completing these steps, you can run the command php -m again to confirm that the DOM extension is enabled, and the output should look like this.

[PHP Modules]

[Zend Modules]
Zend OPcache