Install the PHP DOM Extension on CentOS – the Easiest Way

Here we cover the fastest, most effective way to get the PHP DOM extension installed on CentOS. If you’ve just found out you need to install this extension, but don’t really know what it is, we’ve included some background first.

What is DOM?

“The Document Object Model (DOM) is a cross-platform and language-independent convention for representing and interacting with objects in HTMLXHTML and XML documents.” (Source: DOM in Wikipedia.)

What is PHP DOM extension?

“The DOM extension allows you to operate on XML documents through the DOM API with PHP 5.” (Source: Introduction to the PHP DOM Extension on php.net.)

How to install the PHP DOM Extension on CentOS

You will need superuser privileges. Run the following command:

sudo yum install php-xml

Don’t forget to restart Apache so PHP picks up the new extension:

sudo service httpd restart

How to Check PHP DOM is Installed

You can see PHP DOM is installed by creating a simple web page that calls the phpinfo() function:

<?php phpinfo(); ?>

When you go to this webpage in a browser, you should see this output for the dom extension if it’s installed:

dom

DOM/XMLenabled
DOM/XML API Version20031129
libxml Version2.6.26
HTML Supportenabled
XPath Supportenabled
XPointer Supportenabled
Schema Supportenabled
RelaxNG Supportenabled

Tested on CentOS 5.3.

Tagged , . Bookmark the permalink.

28 Responses to Install the PHP DOM Extension on CentOS – the Easiest Way

  1. Fritz says:

    Thanks! Every other resource I found on installing PHP DOM involved manually installing dependencies, recompiling PHP, etc. You just saved me a bunch of hassle. Apparently, the fact that you can simply do it with YUM is a well-kept secret.

  2. Thanks man, I was triing to install a php script, Get Simple CMS, and allthought simple xml was installed ( on a CentOs 5 with virtualmin ) the DOM API was not.
    the simple

    yum install php-xml

    and apache restart, soved the problem.

  3. Veronica says:

    Ty man looked and spended hours before i came to you site love you.

  4. To do this now, replace ‘php’ with ‘php53′ if you want PHP 5.3.x. There are serious conflicts between standard PHP (5.1.6 at the time of writing) and 5.3. I had to completely clean out php-common, php-mysql, etc and replace them with php53-common and so on.

  5. There’s a small issue in your docu:

    It must be:
    sudo service httpd restart

  6. manish says:

    I have tried this = yum install php-xml
    and showing following errors, please help :
    Loaded plugins: fastestmirror
    Loading mirror speeds from cached hostfile
    * Webmin: webmin.mirror.somersettechsolutions.co.uk
    * atomic: www7.atomicorp.com
    * base: centos.vr-zone.com
    * epel: http://ftp.cuhk.edu.hk
    * extras: centos.vr-zone.com
    * updates: centos.vr-zone.com
    Setting up Install Process
    Resolving Dependencies
    –> Running transaction check
    —> Package php-xml.i386 0:5.3.8-2.el5.art set to be updated
    –> Processing Dependency: php-common = 5.3.8-2.el5.art for package: php-xml
    –> Finished Dependency Resolution
    php-xml-5.3.8-2.el5.art.i386 from atomic has depsolving problems
    –> Missing Dependency: php-common = 5.3.8-2.el5.art is needed by package php-xml-5.3.8-2.el5.art.i386 (atomic)
    Error: Missing Dependency: php-common = 5.3.8-2.el5.art is needed by package php-xml-5.3.8-2.el5.art.i386 (atomic)
    You could try using –skip-broken to work around the problem
    You could try running: package-cleanup –problems
    package-cleanup –dupes
    rpm -Va –nofiles –nodigest
    The program package-cleanup is found in the yum-utils package.

    Waiting for your response ASAP

    • Tasman Hayes says:

      Manish,

      Try this first:

      sudo yum install php-common

      -Taz.

      • Miguel says:

        Hi Tas!

        php-common is already installed but i still cannot yum install php-xml
        ———————-
        Setting up Install Process
        Package matching php-common-5.1.6-27.el5_7.5.x86_64 already installed. Checking for update.
        Nothing to do
        ————————

        ]# yum install php-xml
        Loaded plugins: fastestmirror
        Loading mirror speeds from cached hostfile
        * base: centos.vr-zone.com
        * epel: mirror.nus.edu.sg
        * extras: centos.vr-zone.com
        * updates: centos.vr-zone.com
        Setting up Install Process
        Resolving Dependencies
        –> Running transaction check
        —> Package php-xml.x86_64 0:5.1.6-27.el5_7.5 set to be updated
        –> Processing Dependency: php-common = 5.1.6-27.el5_7.5 for package: php-xml
        –> Processing Dependency: libexslt.so.0()(64bit) for package: php-xml
        –> Processing Dependency: libxslt.so.1()(64bit) for package: php-xml
        –> Running transaction check
        —> Package libxslt.x86_64 0:1.1.17-2.el5_2.2 set to be updated
        —> Package php-xml.x86_64 0:5.1.6-27.el5_7.5 set to be updated
        –> Processing Dependency: php-common = 5.1.6-27.el5_7.5 for package: php-xml
        –> Finished Dependency Resolution
        php-xml-5.1.6-27.el5_7.5.x86_64 from updates has depsolving problems
        –> Missing Dependency: php-common = 5.1.6-27.el5_7.5 is needed by package php-xml-5.1.6-27.el5_7.5.x86_64 (updates)
        Error: Missing Dependency: php-common = 5.1.6-27.el5_7.5 is needed by package php-xml-5.1.6-27.el5_7.5.x86_64 (updates)
        You could try using –skip-broken to work around the problem
        You could try running: package-cleanup –problems
        package-cleanup –dupes
        rpm -Va –nofiles –nodigest
        The program package-cleanup is found in the yum-utils package.

  7. Brian says:

    Have the webtatic repo installed and do the following

    sudo yum –enablerepo=webtatic install php-xml
    service httpd stop
    service httpd start

  8. Dave says:

    you rock. thanks – saved me some time today.

  9. Marat says:

    Thanks Tasman!
    I tested it on Amazon EC2 (with Linux instance) – it works!

    When I installed PHP via yum on Amazon’s Linux, it was compiled with disable-dom option.
    With your instructions I was successful in installing DOM module – thanks!

  10. Pawan Rote says:

    Thanks buddy. it worked.

  11. jpeak5 says:

    Thanks very much!
    Was about to try to recompile php on rhel6.
    Needless to say, this was much better!

  12. enrique says:

    muchas gracias despues de una semana de no poder instalar componente por cierto uso joomla
    ahora si pude faltaba el DOM y aca fue sencillo y efectivo
    muchas gracias

  13. Thanks! says:

    Thank you!. Works.

  14. Simone says:

    Very helpful. Thank you buddy!

  15. Great, this worked like a charm!

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>