← ServerPilot Docs

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").
These instructions only work for Ubuntu 16.04.

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 http://www.saxonica.com/saxon-c/libsaxon-HEC-setup64-v1.1.0.zip
sudo unzip libsaxon-HEC-setup64-v1.1.0.zip

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/libsaxonhec64.so /usr/lib/libsaxonhec64.so
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/ld.so.conf.d/jetvm.conf"
sudo bash -c "echo /usr/lib/rt/lib/amd64 >> /etc/ld.so.conf.d/jetvm.conf"
sudo bash -c "echo /usr/lib/rt/lib/amd64/jetvm >> /etc/ld.so.conf.d/jetvm.conf"
sudo ldconfig

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

/sbin/ldconfig.real: file /usr/lib/libsaxonhec64.so 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 extension=saxon.so > /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:

/etc/php7.2-sp/conf.d/saxon.ini,
Saxon/C
Saxon/C => enabled
Saxon/C EXT version => 1.1.0
Saxon => 9.8.0.3

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: October 8, 2018

Launch your first site in 5 minutes