Categories
CentOS

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/XML enabled
DOM/XML API Version 20031129
libxml Version 2.6.26
HTML Support enabled
XPath Support enabled
XPointer Support enabled
Schema Support enabled
RelaxNG Support enabled

Tested on CentOS 5.3.

28 replies on “Install the PHP DOM Extension on CentOS – the Easiest Way”

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.

Fritz, you are are very welcome! It’s lovely to get a thank you. 🙂

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.

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.

Hi Guido,

Thank you for taking the time to post this info!

Are you using CentOS?
If so, which version?

-Taz.

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

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.

Have the webtatic repo installed and do the following

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

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!

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

JPeak, glad it helped you get PHP DOM installed more easily. 🙂 -Tas.

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

Comments are closed.