Project

Profile

Help

need help installing PHP extension of SaxonC

Added by Wolfhart Totschnig about 2 years ago

Hello,

I have been using SaxonHE for years and would now like to use also SaxonC, specifically the PHP extension. I cannot get the PHP extension to work and therefore would like to ask for your help. I will describe what I did so far, so that you might be able to recognize what went wrong.

I first installed SaxonC on my Ubuntu 16.04 following the instructions at https://www.saxonica.com/saxon-c/documentation11/index.html#!starting/installing/installingLinux

At this stage, I encountered the following problem: The instructions say that, after unzipping the downloaded zip file (libsaxon-HEC-setup64-v11.1.zip in my case), one should "execute the following command to fully unpack the files: ./libsaxon-[EDITION]C-setup64-v[VERSION]". However, there is no such command in the unzipped directory ("bash: ./libsaxon-HEC-setup64-v11.1: No such file or directory"). So I skipped this step and went ahead with copying the core SaxonC installation files to /usr/lib and lastly set the SAXONC_HOME environment variable, as described in the instructions.

The installation of SaxonC seems to have been successful since I can run ./testXPath in the samples/cppTests/ directory, as described here: https://www.saxonica.com/saxon-c/documentation11/index.html#!starting/running However, running this test produces the following output "Test Results - Number of tests= 4, Successes = 3, Failures= 1 Failed tests: testXPathValues". I am wondering whether the failure of one test is significant.

I now proceeded to install the PHP extension as described here: https://www.saxonica.com/saxon-c/documentation11/index.html#!starting/installingphp I encountered the problem that the instructions tell me to start with the command "cd /usr/lib/Saxonica/Saxon-[EDITION]C[VERSION]/Saxon-C-API/", but no such directory exists (i.e., there is no "Saxonica" directory in /usr/lib). So what I did instead was to copy the folder Saxon-C-API from the downloaded directory to /usr/bin, and then I executed the commands indicated in the instructions, namely:

sudo phpize sudo ./configure --enable-saxon sudo make sudo make install

The instructions indicate that only the last command (i.e., make install) should be run with sudo, but I found it necessary to run all of them with sudo.

So I was now hoping that the PHP extension is installed. So I put into my PHP file the following sample code (found here: https://www.saxonica.com/saxon-c/documentation11/index.html#!samples/samples_php):

$saxonProc = new Saxon\SaxonProcessor(); $transformer = $saxonProc->newXslt30Processor(); $executable = $transformer->compileFromString("<xsl:stylesheet version='2.0'" . "xmlns:xsl='http://www.w3.org/1999/XSL/Transform'>" . "<xsl:template name='go'></xsl:template>" . "</xsl:stylesheet>"); $root = $executable->callTemplateReturningValue("go"); $node = $root->getHead()->getNodeValue();

But PHP throws the following error: "Fatal error: Uncaught Error: Class 'Saxon\SaxonProcessor' not found".

What went wrong?

Thank you in advance for your help! Wolfhart


Replies (19)

Please register to reply

RE: need help installing PHP extension of SaxonC - Added by O'Neil Delpratt about 2 years ago

Thanks for reporting your issue. The documentation needs updating.

You can run the PHP commands from any location outside of /usr/lib Therefore you don’t need the sudo command with the exception of ‘sudo make install’

Further down the page there is some details about setting the SAXONC_HOME environment variable. I wonder if this is causing you issue

RE: need help installing PHP extension of SaxonC - Added by Debbie Lockett about 2 years ago

I have opened a bug (https://saxonica.plan.io/issues/5329) to review and update the SaxonC documentation about installation.

Thanks for providing the detailed notes on what worked for you, and what didn't. We clearly need to try out the installation from scratch ourselves, to check and update the instructions, and hopefully get to the bottom of why the installation didn't work for you. I see that you did already follow the instructions to set the SAXONC_HOME environment variable, so I'm not sure if that is actually the issue as O'Neil suggested.

(O'Neil hasn't said it, but he's actually on holiday this week, so apologies if it takes us a little longer than usual to reply to, and resolve, this!)

RE: need help installing PHP extension of SaxonC - Added by Martin Honnen about 2 years ago

Wolfgang, did you edit your php.ini file to enable the Saxon extension with e.g. extension=saxon?

RE: need help installing PHP extension of SaxonC - Added by Martin Honnen about 2 years ago

Wolfhart, sorry for addressing you as "Wolfgang", somehow I misread the prename or my brain went with one that is more common where I live. But the important and essential step to enable the extension in php.ini hopefully helps.

RE: need help installing PHP extension of SaxonC - Added by Wolfhart Totschnig about 2 years ago

Thank you for your replies! I have not been able to resolve the issue with your suggestions, unfortunately. Here is what I tried:

  1. I put "extension=saxon" into php.ini which, on my system, I found in etc/php/7.0/cli. I also tried "extension=saxon.so", which is mentioned in the installation instructions (in the section on PHP5).

  2. I then checked whether the SAXONC_HOME environment variable is set and was surprised to find out that it was not set. I set it (again, since I remember setting it during the installation), but that did not resolve the issue either. I continue to receive the same error message: "Fatal error: Uncaught Error: Class 'Saxon\SaxonProcessor' not found".

Given this experience, I have two concrete questions:

  1. I realized that the SAXONC_HOME environment variable is "unset" at shutdown or startup of the system. How do I need to set it so that it remains set?

  2. Concerning the installation commands (phpize ./configure --enable-saxon make sudo make install): Does it matter that I executed all of them with sudo and not only the last one? Could that be the cause of the problem? Is there a way to check whether these commands produced the desired result?

Thanks again for your help!

RE: need help installing PHP extension of SaxonC - Added by Martin Honnen about 2 years ago

I would think that you neeeded the sudo on all commands because you had moved the files into /usr/lib instead of having them in some of your own directories.

As for checking whether they did work, didn't the last sudo make install show a message that and where it installed the saxon.so for PHP? Did you get any error message there?

As for checking more details, I take it you run PHP 7? What does php --version output?

As for the php.ini, what does php --info | grep 'Configuration File' show?

Does saxon show up as an extension with php --info?

RE: need help installing PHP extension of SaxonC - Added by Wolfhart Totschnig about 2 years ago

Thank you, Martin, for the reply!

As for checking whether they did work, didn't the last sudo make install show a message that and where it installed the saxon.so for PHP? Did you get any error message there?

I don't remember what the exact message was, but it was not an error message. I thought that the process had completed successfully.

As for checking more details, I take it you run PHP 7? What does php --version output?

PHP Warning:  PHP Startup: Unable to load dynamic library '/usr/lib/php/20151012/saxon' - /usr/lib/php/20151012/saxon: cannot open shared object file: No such file or directory in Unknown on line 0
PHP 7.0.33-0ubuntu0.16.04.16 (cli) ( NTS )
Copyright (c) 1997-2017 The PHP Group
Zend Engine v3.0.0, Copyright (c) 1998-2017 Zend Technologies
    with Zend OPcache v7.0.33-0ubuntu0.16.04.16, Copyright (c) 1999-2017, by Zend Technologies

Note that the first line is a warning about Saxon.

As for the php.ini, what does php --info | grep 'Configuration File' show?

PHP Warning:  PHP Startup: Unable to load dynamic library '/usr/lib/php/20151012/saxon' - /usr/lib/php/20151012/saxon: cannot open shared object file: No such file or directory in Unknown on line 0
Configuration File (php.ini) Path => /etc/php/7.0/cli
Loaded Configuration File => /etc/php/7.0/cli/php.ini

Does saxon show up as an extension with php --info?

The output of this command contains the same warning about Saxon as above and then two more lines mentioning Saxon, namely:

SAXONC_HOME => /usr/lib
$_SERVER['SAXONC_HOME'] => /usr/lib

Does that help?

RE: need help installing PHP extension of SaxonC - Added by Martin Honnen about 2 years ago

In my understanding, if the installation had succeeeded, you would have a file /usr/lib/php/20151012/saxon.so, assuming that directory /usr/lib/php/20151012 is where your PHP 7 version has its extensions libraries. So does ls /usr/lib/php/20151012 show lots of .so files, but no saxon.so? I would think that means that part of your installation failed.

I guess you need to repeat it, I can't tell which step failed, when I did the install the last step sudo make install resulted in some message telling where saxon.so was installed, a directory similar to the one you have, just with a different date for the last part as it is a different PHP version (7.4) built on a different day, I think.

RE: need help installing PHP extension of SaxonC - Added by Wolfhart Totschnig about 2 years ago

Here is the output of ls /usr/lib/php/20151012:

build        fileinfo.so  opcache.so   saxon.so      sysvsem.so    xml.so
calendar.so  ftp.so       pdo.so       shmop.so      sysvshm.so    xmlwriter.so
ctype.so     gettext.so   phar.so      simplexml.so  tokenizer.so  xsl.so
dom.so       iconv.so     posix.so     sockets.so    wddx.so
exif.so      json.so      readline.so  sysvmsg.so    xmlreader.so

As you can see, saxon.so is in the folder. It is the only so file that the ls command highlights in green. I am not sure why. At any rate, given that saxon.so is in the folder, it is puzzling that PHP says Unable to load dynamic library '/usr/lib/php/20151012/saxon'. Should the file name maybe be saxon instead of saxon.so?

RE: need help installing PHP extension of SaxonC - Added by Martin Honnen about 2 years ago

Wolfhart, I think you will need to wait whether O'Neil has some idea. I am currently not sure what is wrong.

I am sure the extension has the name saxon.so for me with PHP 7.4 and the php.ini refers only to extension=saxon.

For me ls -al /usr/lib/php/2020/saxon.co lists -rwxr-xr-x 1 root root 1059592 Feb 16 23:36 /usr/lib/php/20190902/saxon.so, perhaps comparing the size and permissions gives a clue.

RE: need help installing PHP extension of SaxonC - Added by Martin Honnen about 2 years ago

The last line should have been

For me ls -al /usr/lib/php/20190902/saxon.co lists -rwxr-xr-x 1 root root 1059592 Feb 16 23:36 /usr/lib/php/20190902/saxon.so, perhaps comparing the size and permissions gives a clue.

RE: need help installing PHP extension of SaxonC - Added by O'Neil Delpratt about 2 years ago

Hi Wolfhart,

In a PHP script please insert the following function:

phpinfo()

Then go to a browser. Do you see Saxon/C in the list?

Also from the commandline you can try the follow to:

php -m | grep saxon -i

You could have a look at the PHP log to see if there are any errors. I usually run the following command:

tail -n 1000 /usr/logs/error_log

Sorry I can't remember the exact location for the error log file but you can try something like the above.

RE: need help installing PHP extension of SaxonC - Added by O'Neil Delpratt about 2 years ago

Also check how many PHP versions you have installed on your machine. If you have more than one you would have to select the one you want to install SaxonC. For example:

phpize -v

Will give you the default version.

If you would like to select a particular version then something like the following should work:

phpize70

RE: need help installing PHP extension of SaxonC - Added by Wolfhart Totschnig about 2 years ago

@Martin: The output of ls -al /usr/lib/php/20151012/saxon.so is

-rwxr-xr-x 1 root root 1065456 feb 15 16:42 /usr/lib/php/20151012/saxon.so

So the same as in your case.

@O'Neil: The only mention of Saxon in the output of phpinfo() is the following:

SAXONC_HOME 	/usr/lib

The output of php -m | grep saxon -i is:

PHP Warning:  PHP Startup: Unable to load dynamic library '/usr/lib/php/20151012/saxon' - /usr/lib/php/20151012/saxon: cannot open shared object file: No such file or directory in Unknown on line 0

The output of phpize -v is:

Configuring for:
PHP Api Version:         20151012
Zend Module Api No:      20151012
Zend Extension Api No:   320151012

Does this help?

RE: need help installing PHP extension of SaxonC - Added by Martin Honnen about 2 years ago

I can't tell why you get that error "Unable to load dynamic library '/usr/lib/php/20151012/saxon' - /usr/lib/php/20151012/saxon: cannot open shared object file: No such file or directory in Unknown on line 0" although the directory contains it.

It seems it has happened to other PHP users with various extensions but I am not able to gather from various posting in various contexts and with various settings what could be issue and how to resolve it, other than that people started playing around with options/uninstallation/reinstallation to see whether that changes and improves things.

RE: need help installing PHP extension of SaxonC - Added by Wolfhart Totschnig about 2 years ago

Reinstallation seems like a good idea. But how do I uninstall the existing extension? I cannot find any information on that in the instructions. Do I just delete the saxon.so file?

RE: need help installing PHP extension of SaxonC - Added by Martin Honnen about 2 years ago

I think as far as PHP is concerned, if you delete /usr/lib/php/20151012/saxon.so and uncomment the extension=saxon, the extension is no longer installed.

As for cleaning up the rest, I don't know whether there is a make clean or similar configured, but better wait for O'Neil anyway, I am afraid I am not skilled to read through Makefiles to tell which actions they contain and which effect they have.

RE: need help installing PHP extension of SaxonC - Added by O'Neil Delpratt about 2 years ago

Hi,

If phpinfo() does not mention about the SaxonC extension then it is not installed or correctly. It seems like its a configuration issue: for example an unset environment variable.

It might be best for us to have a screen share on your machine. You can reach out to me via email and we can arrange a date and time from next week Tuesday or later in the week if that works with you? I hope you can hold out until then.

RE: need help installing PHP extension of SaxonC - Added by Wolfhart Totschnig about 2 years ago

Thank you very much for the offer of a screen share! Yes, Tuesday of next week is soon enough. I will send you an email right away.

    (1-19/19)

    Please register to reply