How to Install the PHP Saxon/C Extension

In the examples shown, replace "X.Y" with your app's PHP version (for example, "5.6" or "7.2").

Saxon/C is a PHP extension for the Saxon/C library that provides processing in XSLT, XQuery, and XPath, as well as schema validation.

To learn more about using this extension, see the PHP API for the Saxon/C extension.

Installing the Saxon/C PHP Extension for PHP 7

In the examples shown, replace "7.X" with your app's PHP version (for example, "7.2").

To install this extension for PHP 7.0, 7.1, or 7.2, SSH into your server as root and run the following commands:

sudo apt-get -y install gcc g++ make autoconf libc-dev pkg-config
sudo apt-get -y install gcj-jdk

Next, run the following commands on your server:

cd /usr/local
sudo wget
sudo unzip

Now, run the command:

sudo ./libsaxon-HEC-setup64-v1.1.0

You will be prompted with:

Enter destination path[/usr/local/Saxonica/Saxon-HEC1.1.0]:

Press Enter.

Once the command completes, run the following commands:

sudo ln -s /usr/local/Saxonica/Saxon-HEC1.1.0/ /usr/lib/
sudo ln -s /usr/local/Saxonica/Saxon-HEC1.1.0/rt /usr/lib/rt
sudo bash -c "echo '# JetVM env path (required for Saxon)' > /etc/"
sudo bash -c "echo /usr/lib/rt/lib/amd64 >> /etc/"
sudo bash -c "echo /usr/lib/rt/lib/amd64/jetvm >> /etc/"
sudo ldconfig

After running the ldconfig command above, you may see the message:

/sbin/ldconfig.real: file /usr/lib/ is truncated

The Saxon developers have said you can ignore this message.

Next, build and install the PHP extension.

cd /usr/local/Saxonica/Saxon-HEC1.1.0/Saxon.C.API/
sudo /opt/sp/php7.X/bin/phpize
sudo PATH=/opt/sp/php7.X/bin:$PATH ./configure --enable-saxon
sudo make
sudo make install

When the above commands complete, run the following command once for each app that will use Saxon. Repeat the command for each app. Replace APPNAME with the name of the app.

sudo bash -c "echo env[LD_LIBRARY_PATH] = /usr/lib/rt/lib/amd64:/usr/lib/rt/lib/amd64/jetvm > /etc/php7.X-sp/fpm-pools.d/APPNAME.d/saxon_ld_library_path.conf"

Finally, create a configuration file for the extension and restart PHP by running the following commands:

sudo bash -c "echo > /etc/php7.X-sp/conf.d/saxon.ini"
sudo service php7.X-fpm-sp restart

Installing Saxon/C on PHP 5

According to the official documentation, "for PHP5 please copy files in the PHP5-Build directory into the Saxon.C.API directory." However, there is no PHP5-Build directory provided. Please contact Saxonica's support for assistance with building for PHP 5.

Verifying the Installation

You can verify Saxon/C is installed correctly by running the command:

phpX.Y-sp -i | grep saxon

You should see the following output:

Saxon/C => enabled
Saxon/C EXT version => 1.1.0
Saxon =>

Uninstalling the Saxon/C Extension

To uninstall this extension, as root run the command:

sudo rm /etc/phpX.Y-sp/conf.d/saxon.ini

Next, restart PHP-FPM with the command:

sudo service phpX.Y-fpm-sp restart

Last updated: March 08, 2018