phpubuntuodbcsqlanywhere

www-data not able to find ODBC drivers


I am very new to Linux, ODBC and php in general but most of the times I manage to resolve the issues I run into. Until now.

We run a Linux/Ubuntu server and I have a php script that should talk to an external (readonly) SQL anywhere 17 database via ODBC. I managed to get this working once, but then managed to crash it all and now even after restoring to a working snapshot I can't get it working again.

lrwxrwxrwx 1 root     root          18 Feb 28 10:13 libdbodbc17_r.so -> libdbodbc17_r.so.1
-rwxr-xr-x 1 www-data www-data 1804560 Feb 28 10:13 libdbodbc17_r.so.1

Running isql from terminal:

sudo -u www-data isql -v DSN UID PASSWORD
[01000][unixODBC][Driver Manager]Can't open lib '/opt/sqlanywhere17/lib64/libdbodbc17_r.so' : file not found
[ISQL]ERROR: Could not SQLConnect

I added the line export LD_LIBRARY_PATH=/opt/sqlanywhere17/lib64 into /etc/apache2/envvars to make sure apache is looking in the right library.

It seems to partially resolve the issue, but introduces me to a new issue:

[IM004][unixODBC][Driver Manager]Driver's SQLAllocHandle on SQL_HANDLE_HENV failed [ISQL]ERROR: Could not SQLConnect

This, I can not wrap my head around why or where its coming from.

Running ISQL as logged on terminal user (not root): logged on user

Strace trying connection as www-data

Strace as logged on user


Solution

  • I somehow managed resolve this now.

    In my strace logs I noticed an error indicating the system was looking for the file dblgen17.res in the folder /opt/sqlanywhere17/lib64. This file did not exist in this folder, instead it was located in the folder: /opt/sqlanywhere17/res/

    I copied the filed over to /lib64. Got another error:

    [08001][unixODBC][SAP][ODBC Driver][SQL Anywhere]Encryption error: Missing or invalid encryption DLL "libdbrsa17_r.so"
    

    Did a sudo chmod 644 /opt/sqlanywhere17/lib64/libdbrsa17_r.so and voila. Success

    My wild guess is that apache somehow need those files to connect, while local users on the server does not.

    It might not be the correct way of resolving the issue, but atleast apache can now function with ODBC as intended.