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 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.
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:
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.
(Addition, Jan. 29, 2018, 6:02 PM EST. I found out today that one old version of PHP that definitely doesn't work with this blog post's instructions is PHP 5.2.17. So, I don't know if it's possible to get Saxon/C to work with such an old version of PHP.)
Here's how I made Saxon/C into a PHP extension.
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:
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.
./configure --enable-saxon
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.
In "Makefile", find line 31, which looks like this:
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):
Otherwise, without that symlink, "make" will eventually fail with this error:
After "make" succeeds, the compiled "saxon.so" PHP extension will be in the "modules" folder.
For me, that folder was:
In the extensions section of your "php.ini" file, put a line like this:
In my system, the "rt" folder was in this folder, but it will probably be elsewhere on your system:
You can even run the phpinfo(); command from a terminal window with this command line:
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:
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.
Then, Saxon/C works fine for me.
Then, I don't even need to add anything to my PHP scripts for them to just work.
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:
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.
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.
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.
./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]:
Saxon-HEC 1.0.2 has been successfully installed on your computer.
phpize
So, to let "make" know where to find those files, I had to edit the "Makefile" in a text editor.
CPPFLAGS = -DHAVE_CONFIG_H
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/
/usr/lib/
folder, pointing to the "libsaxonhec.so" file in the "Saxonica/Saxon-HEC1.0.2/" folder.
make
/usr/local/lib/php/extensions
/etc/php.ini
and one at /usr/local/lib/php.ini
.
extension=saxon.so
/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).
/root/00-ApWorkspace/Saxonica/Saxon-HEC1.0.2
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.
/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.
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):
Another workaround is to add this to Hiawatha's config file (which, on my system, is at /usr/local/etc/hiawatha/hiawatha.conf):
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.