Home / PHP Error Class ‘XsltProcessor’ not found

PHP Error Class ‘XsltProcessor’ not found

If you get the following error message in PHP then it means you need to have the XSL extension installed. Obviously the /path/to/file.php will be the actual path and filename of the PHP script the error occured in, and the line number will be the actual line. The PHP manual says that "PHP 5 includes the XSL extension by default" but one of my CentOS 5 installations it didn’t seem to be; the following post looks at how to install this extension on CentOS 5. It will also work on Red Hat Enterprise Linux and should also work on Fedora and any other derivative Linux distributions.

Fatal error: Class 'XsltProcessor' not found in /path/to/file.php on line 138

The package that needs to be installed on CentOS 5 to enable the XSL extension is php-xml. You can either install it using one of the GUI software installation tools, or from the command line. This post looks at how to install the extension on the command line.

Run the following command, either as the root user, or using sudo:

yum install php-xml

After hitting the <enter> key you’ll see some output like this:

Loading "installonlyn" plugin
Setting up Install Process
Setting up repositories
Reading repository metadata in from local files
Parsing package install arguments
Resolving Dependencies
--> Populating transaction set with selected packages. Please wait.
---> Downloading header for php-xml to pack into transaction set.
php-xml-5.1.6-15.el5.i386 100% |=========================|  17 kB    00:00
---> Package php-xml.i386 0:5.1.6-15.el5 set to be updated
--> Running transaction check

Dependencies Resolved

=============================================================================
 Package                 Arch       Version          Repository        Size
=============================================================================
Installing:
 php-xml                 i386       5.1.6-15.el5     base               93 k

Transaction Summary
=============================================================================
Install      1 Package(s)
Update       0 Package(s)
Remove       0 Package(s)

Total download size: 93 k
Is this ok [y/N]:

At this point you type in "Y" and hit <enter>. It will then install the XSL extension for PHP:

Downloading Packages:
(1/1): php-xml-5.1.6-15.e 100% |=========================|  93 kB    00:00
warning: rpmts_HdrFromFdno: Header V3 DSA signature: NOKEY, key ID e8562897
Importing GPG key 0xE8562897 "CentOS-5 Key (CentOS 5 Official Signing Key) <centos-5-key@centos.org>" from http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-5
Is this ok [y/N]: y
Running Transaction Test
Finished Transaction Test
Transaction Test Succeeded
Running Transaction
  Installing: php-xml                      ######################### [1/1]

Installed: php-xml.i386 0:5.1.6-15.el5
Complete!

The installation is now complete. However, you still can’t use the XSLTProcessor class and other related XML functions until you have reloaded the Apache web server like so, using either sudo or running it as root:

/etc/init.d/httpd reload

Note that just doing a "reload" seems to work OK, it doesn’t have to be a full "restart".

This is how to install the XSL extension for PHP from the command line using Fedora, CentOS or Red Hat’s Enterprise Linux and other Linux deritives. The process and package name will be similar using other Linux and BSD distros.