Note by Apollia on Nov. 8, 2023: Please join my Patreon if you'd like to support me and my work!

My main personal website is now Apollia.org. I'm still not sure what to do with Astroblahhh.Com, so it's mostly staying as-is for now.





Puppy Linux Blog Post:

How to make Saxon/C v1.0.2 into a PHP extension for PHP 5.6.13 in Lucid Puppy Linux 5.2.8
9/19/2016

Post Below
9/19/2016 - How to make Saxon/C v1.0.2 into a PHP extension for PHP 5.6.13 in Lucid Puppy Linux 5.2.8 (Puppy Linux)

    Hide/Show:


   ▲ Top  ▼ Bottom  △ TOC
How to make Saxon/C v1.0.2 into a PHP extension for PHP 5.6.13 in Lucid Puppy Linux 5.2.8
Monday, September 19th, 2016
19:15:31 GMT

Puppy Linux

I wanted to be able to use XSLT 2.0 with PHP (my favorite programming language), so I figured out how to compile Saxon/C into a PHP extension.

According to Saxon/C's official home page, Saxon/C provides "XML document processing for the C/C++/PHP platforms", and "In particular, Saxon/C provides processing in XSLT, XQuery and XPath, and Schema validation".


I ran into a few problems trying to make Saxon/C into a PHP extension on my Lucid Puppy Linux 5.2.8 version 004 system, but, fortunately, I was able to solve them.

I still didn't figure out how to make all of the Saxon/C example PHP scripts work, but, 3 out of 4 work fine for me.




To compile software from scratch in Puppy Linux, it's often necessary (or convenient) to use the DevX file of development tools for your Puppy Linux.

My page of Some Puppy Linux Basics explains more about DevX files, and if you need the DevX for Lucid Puppy 5.2.8, it's available at this link:

http://distro.ibiblio.org/puppylinux/puppy-5.2.8/

If you're using a different version of Puppy than Lucid Puppy 5.2.8, that DevX probably won't work, so you should instead download the DevX released for your Puppy.

Also, if you're not using Lucid Puppy 5.2.8, please bear in mind that the instructions in this blog post might not all apply or work for you, since different Puppy Linux distros, and probably even different versions of the same Puppy distro, can differ quite substantially from each other.

And here's how to load SFS files.




Here's a list of required other software. Perhaps slightly different versions would also work, but these are exactly what I used.




The below instructions assume you already have PHP 5.6.13 and Java 1.8.0_51 installed.

Here's how I made Saxon/C into a PHP extension.


  1. Unzip the file "libsaxon-HEC-setup-v1.0.2.zip" to whatever folder you want.

  2. Open a terminal window in that folder, and type this command:

    ./libsaxon-HEC-setup-v1.0.2


    That program will then give you a prompt that looks something like this:

    Enter destination path[/root/00-ApWorkspace/Saxonica/Saxon-HEC1.0.2]:

    You can press Enter on your keyboard to accept the default path, or type in a different path. If all goes well, a list of files that are being installed will be printed, and in the end, it will say:

    Saxon-HEC 1.0.2 has been successfully installed on your computer.


  3. Next, open the Saxonica folder, then the Saxon-HEC1.0.2 folder.

    There's a "readme.md" file you can read if you want.

    There's also a "php-library-module" folder, containing "saxon.so", an already-built PHP extension. It might work if you happen to be using the version of PHP the Saxon/C home page says that extension was built for - PHP 5.5.9. But, I tried it with PHP 5.6.13, and it didn't work for me.


  4. Open the Saxon.C.API folder, then open a terminal window in that folder, and type these commands. (The "phpize" command will only work if you have PHP installed):

    phpize

    ./configure --enable-saxon


  5. Here's where I had to diverge from the instructions in the "readme.md" file.

    Originally, running "make" didn't succeed for me because I had Java installed in an unconventional place, and "make" needed two Java-related files which "make" couldn't find: "jni.h" and "jni_md.h" (and probably others as well).

    "make" also needed a file from somewhere in the Saxon-HEC1.0.2 folder.


    So, to let "make" know where to find those files, I had to edit the "Makefile" in a text editor.

    In "Makefile", find line 31, which looks like this:

    CPPFLAGS = -DHAVE_CONFIG_H

    Change that to something like this (but customize it with the paths where you have Java, and where you put the Saxon-HEC1.0.2 folder):

    CPPFLAGS = -DHAVE_CONFIG_H -I/root/apbin/Java/v8u51/include/ -I/root/apbin/Java/v8u51/include/linux/ -I/root/00-ApWorkspace/Saxonica/Saxon-HEC1.0.2/


  6. Added Dec. 20, 2016, 12:50 AM EST. (Sorry, I forgot to mention this step before!) Next, to make it so the "make" command will succeed, you must put a symlink inside the /usr/lib/ folder, pointing to the "libsaxonhec.so" file in the "Saxonica/Saxon-HEC1.0.2/" folder.

    Otherwise, without that symlink, "make" will eventually fail with this error:


  7. Next, in a terminal window opened at the Saxon.C.API folder, type this command:

    make

    After "make" succeeds, the compiled "saxon.so" PHP extension will be in the "modules" folder.


  8. Open the "modules" folder. Then, go to wherever your folder of PHP extensions is, and copy "saxon.so" into that folder.

    For me, that folder was:

    /usr/local/lib/php/extensions


  9. Then, to enable the saxon.so extension in PHP, edit your "php.ini" file. You might have multiple php.ini files - I have one at /etc/php.ini and one at /usr/local/lib/php.ini.

    In the extensions section of your "php.ini" file, put a line like this:

    extension=saxon.so


  10. I also had to create a symlink at /usr/lib/rt/ pointing to the "rt" folder in the "Saxon-HEC1.0.2" folder, since otherwise, errors happened, sometimes with PHP, and sometimes with the Hiawatha web server (which sometimes gave me an Internal Server Error).

    In my system, the "rt" folder was in this folder, but it will probably be elsewhere on your system:

    /root/00-ApWorkspace/Saxonica/Saxon-HEC1.0.2


  11. To make sure the extension was installed successfully, you can have PHP run the phpinfo(); command to print a list of installed PHP extensions and other info.

    You can even run the phpinfo(); command from a terminal window with this command line:

    php -r "phpinfo();"


There are example PHP scripts in the folder Saxon-HEC1.0.2/samples/php. "xpathExamples.php", "xqueryExamples.php", and "xsltExamples.php" worked fine for me, but "validatorExamples.php" had an error which I don't yet know how to fix.

Also, I think I ran into Bug #2677 - Saxon/C PHP API getErrorMessage does not report useful error.

However, more detailed error messages are readable in my Hiawatha web server logs, which, on my system, are located at:

/usr/local/var/log/hiawatha/error.log


I made this little PHP script called display_last_5_lines_of_hiawatha_error_log.php to make that log easier to read in my web browser:


Additions, March 12, 2017, 5:36 PM/6:14 PM EDT. While trying to use the Saxon/C PHP extension in Lighthouse 64 Puppy Linux 6.02 Beta 2, I had trouble making it work in the Hiawatha web server, even after doing all of the above.

Even with /usr/lib64/libsaxonhec.so (another other paths) symlinked to my system's location for libsaxonhec.so (/root/apbin/Saxon-HEC/Saxonica/Saxon-HEC1.0.2/libsaxonhec.so), I kept getting Internal Server Errors, and Hiawatha's log said, "Unable to load /usr/lib64/libsaxonhec." and "Error: : No such file or directory".

I think this might be related to Bug #2907 - php saxon.so is looking for libsaxonhec.so without so extension in both /usr/lib64 and /usr/lib and failing.


Fortunately, that bug page helped me figure out a workaround. In every PHP script which needs to run Saxon/C, I can put this line (which you'll probably need to customize with the path to where libsaxonhec.so is on your system):

Then, Saxon/C works fine for me.


Another workaround is to add this to Hiawatha's config file (which, on my system, is at /usr/local/etc/hiawatha/hiawatha.conf):

Then, I don't even need to add anything to my PHP scripts for them to just work.


Yet another workaround is to not even use a web server (which I usually prefer anyway, at least on any of my internet-connected computers). Then, you can either set the SAXONC_HOME environment variable before you run PHP, or, you can set it from inside your PHP script using the PHP line above.

I made a couple scripts to make it easier to view PHP script output in your web browser without having to use a web server:

https://github.com/Apollia/Without-web-server-run-PHP-script-and-view-output-in-web-browser

   ▲ Top  ▼ Bottom  △ TOC


    Hide/Show:





Note by Apollia on Nov. 8, 2023: Please join my Patreon if you'd like to support me and my work!

My main personal website is now Apollia.org. I'm still not sure what to do with Astroblahhh.Com, so it's mostly staying as-is for now.