PHP SDK setup failing

Product:
PDFTron PHP SDK

Product Version:
Not sure. Following the steps here: https://www.pdftron.com/documentation/php/get-started/integration/linux/
Platform: Ubuntu 18.04.6 (on Windows 10 WSL2)

Please give a brief summary of your issue:
PHP SDK setup failing - libPDFNetC.so: cannot open shared object file

Please describe your issue and provide steps to reproduce it:
Followed all the steps that are mentioned here. Steps for SWIG were not available though in the Getting Started section though.

Full error:
/home/nik/PDFTron/PDFNetWrappers/PDFNetC/Lib/PDFNetPHP.so’ (tried: /home/nik/PDFTron/PDFNetWrappers/PDFNetC/Lib/PDFNetPHP.so (libPDFNetC.so: cannot open shared object file: No such file or directory), /usr/lib/php/20190902//home/nik/PDFTron/PDFNetWrappers/PDFNetC/Lib/PDFNetPHP.so.so (/usr/lib/php/20190902//home/nik/PDFTron/PDFNetWrappers/PDFNetC/Lib/PDFNetPHP.so.so: cannot open shared object file: No such file or directory))

Had tried the steps in the troubleshooting section. None of them helped. enable_dl is turned on.

Thanks!

@Ryan @Correy_Lim
Any help here would allow me to evaluate the service.

Thanks!

@Ryan @Correy_Lim

Can you let me know if you would be able to assist with the SDK setup?

Hello Nikhil,

Happy to provide assistance with the issue you’re facing.

The error you’ve noted here:

/home/nik/PDFTron/PDFNetWrappers/PDFNetC/Lib/PDFNetPHP.so (libPDFNetC.so: cannot open shared object file: No such file or directory),

Is an indication that the dynamic library PDFNetPHP.so is unable to find the PDFNet compiled library, originating from:

http://www.pdftron.com/downloads/PDFNetC64.tar.gz

To ensure we’re on the same page, can you help us understand what is in your current working directory where you are trying to build the PHP bindings? Particularly, if you could run this command in the directory where the PHP build is being done:

ls -lh .

I’d expect the directories originating from PDFNetC64/Headers and PDFNetC64/Lib/ to be there, per steps 3 and 4 of our guide:

PHP PDF Library for Linux | PDFTron SDK

May I also ask what command you ran to trigger the full error you provided? I’d be happy to provide further guidance once I have a better understanding of the current situation.

1 Like

Thanks for initiating the troubleshooting @Correy_Lim.

To ensure we’re on the same page, can you help us understand what is in your current working directory where you are trying to build the PHP bindings?

Here are the contents of Build folder:

nik@DESKTOP-B3CS5F7:~/PDFTron/PDFNetWrappers/Build$ ls -lh .
total 44K
-rw-r--r-- 1 nik  nik   14K Sep 30 18:18 CMakeCache.txt
drwxr-xr-x 4 nik  nik  4.0K Sep 30 18:18 CMakeFiles
-rw-r--r-- 1 nik  nik  6.4K Sep 30 18:18 Makefile
drwxr-xr-x 3 nik  nik  4.0K Sep 30 18:30 PDFNetPHP
-rw-r--r-- 1 nik  nik  1.9K Sep 30 18:18 cmake_install.cmake
-rw-r--r-- 1 root root  215 Sep 30 18:18 install_manifest.txt
drwxr-xr-x 2 nik  nik  4.0K Sep 30 18:18 lib

Contents of PDFNetC folder:

nik@DESKTOP-B3CS5F7:~/PDFTron/PDFNetWrappers/PDFNetC$ ls -lh .
total 39M
drwxr-xr-x 10 nik nik 4.0K Aug 25 00:11 Headers
drwxr-xr-x  5 nik nik 4.0K Sep 30 18:18 Lib
drwxr-xr-x  5 nik nik 4.0K Sep 30 17:38 PDFNetC64
-rw-r--r--  1 nik nik  39M Aug 25 03:34 PDFNetC64.tar.gz
-rw-r--r--  1 nik nik   49 Sep 30 17:37 README.txt

May I also ask what command you ran to trigger the full error you provided?

When attempting to run php in interactive mode from the command line, the error is triggered.

php -a

In case it helps, here are the php.ini contents:

enable_dl = On
extension=/home/nik/PDFTron/PDFNetWrappers/PDFNetC/Lib/PDFNetPHP.so

Do let me know if additional info is required.

Looking forward to start experimenting with the SDK.

Hello Nikhil,

Thanks for providing all the information that you have, I am in the process of setting up my environment to try and replicate this issue, but in the meantime, may I ask if inside of the directory /home/nik/PDFTron/PDFNetWrappers/PDFNetC/Lib/ (i.e. where PDFNetPHP.so resides), is libPDFNetC.so also in that directory? If not, can you try copying the libPDFNetC.so dynamic library into /home/nik/PDFTron/PDFNetWrappers/PDFNetC/Lib/ to see if then PDFNetPHP.so is able to resolve this issue:

/home/nik/PDFTron/PDFNetWrappers/PDFNetC/Lib/PDFNetPHP.so (libPDFNetC.so: cannot open shared object file: No such file or directory)

In the meantime, I will let you know once I’ve had a chance to try and replicate this issue, but please let me know what the results of my above suggestion are in the meantime when you have a moment.

1 Like

Yes, here are the contents of the directory:

nik@DESKTOP-B3CS5F7:~/PDFTron/PDFNetWrappers/PDFNetC/Lib$ ll
total 54M
drwxr-xr-x 5 nik  nik  4.0K Sep 30 18:18 ./
drwxr-xr-x 5 nik  nik  4.0K Sep 30 17:38 ../
-rw-r--r-- 1 nik  nik  467K Aug 25 00:26 PDFNet.jar
-rw-r--r-- 1 root root  198 Sep 30 17:37 PDFNetPHP.php
-rwxrwxrwx 1 root root 6.9M Sep 30 18:18 PDFNetPHP.so*
-rw-r--r-- 1 root root 592K Sep 30 18:18 PDFNetPHP_core.php
-rwxr-xr-x 1 nik  nik   46M Aug 25 00:26 libPDFNetC.so*
-rw-r--r-- 1 nik  nik   852 Aug 25 00:26 libinfo.txt
drwxr-xr-x 2 nik  nik  4.0K Aug 25 00:45 net5.0/
drwxr-xr-x 2 nik  nik  4.0K Aug 25 00:45 netcoreapp2.1/
drwxr-xr-x 2 nik  nik  4.0K Aug 25 00:45 netstandard2.1/

Hope that helps. Looking forward to know your setup experience and resolve this.

Thanks!

@Correy_Lim
As noticeable in my previous comment, the libPDFNetC.so is in the expected location.
Do let me know if in addition to my previous comment any new info is required.

Thanks!

Hi Nikhil,

One thing I do notice in your directories is that the .so files are owned by the root user. Could you please ensure that they can be accessed by the user that is running the PHP application (for example, like www-root, or http).

Hello Nikhil,

I am still working on creating a PHP build in a similar environment as yours, and I will get back to you as soon as I have completed this work, but if you could try Shakthi’s recommendation in the meantime and let us know the results, it would be greatly appreciated!

Sure @shakthi124. Changed ownership to nik. But, I think since read permissions existed on all, this might not be an issue.

nik@DESKTOP-B3CS5F7:~/PDFTron/PDFNetWrappers/PDFNetC/Lib$ ll
total 54M
drwxr-xr-x 5 nik  nik  4.0K Sep 30 18:18 ./
drwxr-xr-x 5 nik  nik  4.0K Sep 30 17:38 ../
-rw-r--r-- 1 nik  nik  467K Aug 25 00:26 PDFNet.jar
-rw-r--r-- 1 root root  198 Sep 30 17:37 PDFNetPHP.php
-rwxrwxrwx 1 nik  nik  6.9M Sep 30 18:18 PDFNetPHP.so*
-rw-r--r-- 1 root root 592K Sep 30 18:18 PDFNetPHP_core.php
-rwxr-xr-x 1 nik  nik   46M Aug 25 00:26 libPDFNetC.so*
-rw-r--r-- 1 nik  nik   852 Aug 25 00:26 libinfo.txt
drwxr-xr-x 2 nik  nik  4.0K Aug 25 00:45 net5.0/
drwxr-xr-x 2 nik  nik  4.0K Aug 25 00:45 netcoreapp2.1/
drwxr-xr-x 2 nik  nik  4.0K Aug 25 00:45 netstandard2.1/

The same error is returned.

nik@DESKTOP-B3CS5F7:~/PDFTron/PDFNetWrappers/PDFNetC/Lib$ php -a
PHP Warning:  PHP Startup: Unable to load dynamic library '/home/nik/PDFTron/PDFNetWrappers/PDFNetC/Lib/PDFNetPHP.so' (tried: /home/nik/PDFTron/PDFNetWrappers/PDFNetC/Lib/PDFNetPHP.so (libPDFNetC.so: cannot open shared object file: No such file or directory), /usr/lib/php/20190902//home/nik/PDFTron/PDFNetWrappers/PDFNetC/Lib/PDFNetPHP.so.so (/usr/lib/php/20190902//home/nik/PDFTron/PDFNetWrappers/PDFNetC/Lib/PDFNetPHP.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0
Interactive mode enabled

@Correy_Lim FYI.

@Correy_Lim

I understand you are reproducing this on your end. Did you also experience the same error?

Thanks!

Hell @qwertynik,

Apologies for the delayed response, I was indeed working on trying to reproduce this and I was getting close to finishing the build and being able to run PHP sample code with our library, but was side-tracked by other urgent matters, but I have time to get back to this today, so I will get back to you soon today.

Hello Nikhil,

I’ve followed all the instructions available here:

PHP PDF Library for Linux | PDFTron SDK

On WSL running Ubuntu, and I was successfully able to get our PHP build working:

I took a look at the latest error you reported again here:

PHP Warning:  PHP Startup: Unable to load dynamic library '/home/nik/PDFTron/PDFNetWrappers/PDFNetC/Lib/PDFNetPHP.so' (tried: /home/nik/PDFTron/PDFNetWrappers/PDFNetC/Lib/PDFNetPHP.so (libPDFNetC.so: cannot open shared object file: No such file or directory), /usr/lib/php/20190902//home/nik/PDFTron/PDFNetWrappers/PDFNetC/Lib/PDFNetPHP.so.so (/usr/lib/php/20190902//home/nik/PDFTron/PDFNetWrappers/PDFNetC/Lib/PDFNetPHP.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0

One thing that caught my eye was this:

/home/nik/PDFTron/PDFNetWrappers/PDFNetC/Lib/PDFNetPHP.so.so

I notice the filename is PDFNetPHP.so, but in your previous example where you provided a listing of the directory:

nik@DESKTOP-B3CS5F7:~/PDFTron/PDFNetWrappers/PDFNetC/Lib$ ll
total 54M
drwxr-xr-x 5 nik  nik  4.0K Sep 30 18:18 ./
drwxr-xr-x 5 nik  nik  4.0K Sep 30 17:38 ../
-rw-r--r-- 1 nik  nik  467K Aug 25 00:26 PDFNet.jar
-rw-r--r-- 1 root root  198 Sep 30 17:37 PDFNetPHP.php
-rwxrwxrwx 1 nik  nik  6.9M Sep 30 18:18 PDFNetPHP.so*
-rw-r--r-- 1 root root 592K Sep 30 18:18 PDFNetPHP_core.php
-rwxr-xr-x 1 nik  nik   46M Aug 25 00:26 libPDFNetC.so*
-rw-r--r-- 1 nik  nik   852 Aug 25 00:26 libinfo.txt
drwxr-xr-x 2 nik  nik  4.0K Aug 25 00:45 net5.0/
drwxr-xr-x 2 nik  nik  4.0K Aug 25 00:45 netcoreapp2.1/
drwxr-xr-x 2 nik  nik  4.0K Aug 25 00:45 netstandard2.1/

It is PDFNetPHP.so and not PDFNetPHP.so.so. Could this be the problem? Is the absolute path to PDFNetPHP.so perhaps incorrectly written as PDFNetPHP.so.so in your php.ini file?

Thanks for the detailed response @Correy_Lim.

Had a similar question as you had. However, after reinspecting the error, realized that it is PHP’s mechanism to look for the extension at different possible places. First it looks for the extension at
/home/nik/PDFTron/PDFNetWrappers/PDFNetC/Lib/PDFNetPHP.so
and then at
/home/nik/PDFTron/PDFNetWrappers/PDFNetC/Lib/PDFNetPHP.so.so
I assume this is to support the use-case where someone might miss entering .so in the php.ini file.

The steps for setting up the SDK stated that SWIG needs to be installed. However, since the steps to do the same were missing, had installed it myself with some research on Google. Here are the version numbers of both PHP and SWIG:

nik@DESKTOP-B3CS5F7:/mnt/c/Users/syste$ swig -version

SWIG Version 3.0.12

Compiled with g++ [x86_64-pc-linux-gnu]

Configured options: +pcre

Please see http://www.swig.org for reporting bugs and further information
nik@DESKTOP-B3CS5F7:/mnt/c/Users/syste$ php -v
PHP Warning:  PHP Startup: Unable to load dynamic library '/home/nik/PDFTron/PDFNetWrappers/PDFNetC/Lib/PDFNetPHP.so' (tried: /home/nik/PDFTron/PDFNetWrappers/PDFNetC/Lib/PDFNetPHP.so (libPDFNetC.so: cannot open shared object file: No such file or directory), /usr/lib/php/20190902//home/nik/PDFTron/PDFNetWrappers/PDFNetC/Lib/PDFNetPHP.so.so (/usr/lib/php/20190902//home/nik/PDFTron/PDFNetWrappers/PDFNetC/Lib/PDFNetPHP.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0
PHP 7.4.24 (cli) (built: Sep 23 2021 21:35:51) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
    with Zend OPcache v7.4.24, Copyright (c), by Zend Technologies
    with Xdebug v3.0.4, Copyright (c) 2002-2021, by Derick Rethans

Not sure what’s failing here. The relatively complex part of the setup, building the so file, appears to be complete. But the usage of the extension is failing.

Excerpts from the php.ini file:

Thanks!

Hello Nik,

Thank you for your response. Just to confirm, were you able to run the samples at all by calling the RunTest.sh batch to confirm if the module loads properly? I see now you are just getting this message as a warning when you run PHP in interactive mode.

1 Like

@shakthi124

Did not run the RunTest.sh. Will do so and post the results here.

Thanks!

Great idea @shakthi124. Finally a way out of what seemed to be going nowhere.
Will experiment more with the tests and let you know. Ran one of the tests and for some cases it printed ‘Done’. So assuming it is working.
Not sure as to why no warning was printed, probably it is suppressed in the test files. The warning from PHP regarding library load failure is at best misleading.