ZF4 Blog

Installing the Saxon/C PHP Extension

XSLT support for PHP is limited to XSLT Version 1.
The standard has moved on and it appears that PHP is not about to catch up any time soon. You can get round this at the expense of a little bit of heavy lifting on your part.

Saxonica, home of the Saxon family of XSLT and XQuery processors, have by virtue of their Saxon/C library, provided a PHP extension that can be used to give access to XSLT V2. The basics of installation are provided here, but I found that I had to do a couple of extra things to get it up and running, so this post is about installing on an Ubuntu 64 bit system (mine is Linux Mint 17) running PHP 5.5

If it helps, then it works! However, knowing from experience that everyone's setup can be slightly different, please comment on this post if you find inconsistencies etc. It would be helpful if you could note your OS, version, flavour etc.

sudo to root now.

Install dependencies

This assumes you already have Apache installed (although technically, this isn't necessary, you can run this stuff in cli mode.)

    apt-get install openjdk-7-jdk build-essential php5-dev gcj-jdk

Install and build Saxon/C

Download and unzip your platform Saxon/C.

Run the installation and specify your target directory as /usr/lib: NB. The official documentation is wrong, the installer will install to Saxonica/

Own it to root and allow read access to others:

    chown -R root /usr/lib/Saxonica
    chmod -R u+r /usr/lib/Saxonica

Link the dynamic saxon library so it can be found:

    ln -s /usr/lib/Saxonica/Saxon-HEC0.3.1/libsaxon.so /usr/lib/libsaxon.so

Link the jetvm library so it can be found:

    ln -s /usr/lib/Saxonica/Saxon-HEC0.3.1/rt /usr/lib/rt

create the LD config file for Jetvm (I use nano, use whatever editor you are familiar with):

    nano /etc/ld.so.conf.d/jetvm.conf

and add the contents:

    #JetVM env path - required for Saxon
    /usr/lib/Saxonica/Saxon-HEC0.3.1/rt/lib/amd64
    /usr/lib/Saxonica/Saxon-HEC0.3.1/rt/lib/amd64/jetvm

save the file and run ldconfig:

    ldconfig

Edit apache's environment:

    nano /etc/apache2/envvars

and add to the end of the file:

    ## Saxonica Saxon HE support
    export LD_LIBRARY_PATH=/usr/lib/Saxonica/Saxon-HEC0.3.1/rt/lib/amd64:/usr/lib/Saxonica/Saxon-HEC0.3.1/rt/lib/amd64/jetvm:$LD_LIBRARY_PATH

save the file.

Build and install the PHP extension

    cd /usr/lib/Saxonica/Saxon-HEC0.3.1/Saxon-C-API/
    phpize
    ./configure --enable-saxon
    make
    make install

Create a module conf file:

    nano /etc/php5/mods-available/saxon.ini

and add contents:

    ; configuration for php Saxon HE module
    extension=saxon.so

save the file.

Enable the module for PHP:

    php5enmod saxon

Restart Apache

If you are running Apache then:

    service apache2 restart

Check it is loaded

    php -m | grep saxon -i

should display

    Saxon/C

E&OE

Now it's time for a curry!

p.s. You may find these links helpful: