microsoft / msphpsql

Microsoft Drivers for PHP for SQL Server
MIT License
1.8k stars 374 forks source link

Can't open lib libmsodbcsql-18.0.so.1.1 file not found #1388

Closed kosmic7 closed 2 years ago

kosmic7 commented 2 years ago

I've been trying to fix this for a week now but getting nowhere. Any help much much appreciated!!!

Ubuntu 18.04 PHP 7.4.29 Microsoft ODBC 18 PHP sqlsrv and pdo-sqlsrv version 5.10.0 (I think? not sure how to tell)

I installed MS ODBC and PHP-FPM drivers using instructions here: https://docs.microsoft.com/en-us/sql/connect/php/installation-tutorial-linux-mac?view=sql-server-ver15

I'm getting this error when using sqlsrv_connect(): [unixODBC][Driver Manager]Can't open lib '/opt/microsoft/msodbcsql18/lib64/libmsodbcsql-18.0.so.1.1' : file not found

I have verified that the file exists and that I have permission to access it:

$ odbcinst -q -d -n "ODBC Driver 18 for SQL Server"
[ODBC Driver 18 for SQL Server]
Description=Microsoft ODBC Driver 18 for SQL Server
Driver=/opt/microsoft/msodbcsql18/lib64/libmsodbcsql-18.0.so.1.1
UsageCount=1
ls -l /opt/microsoft/msodbcsql18/lib64/libmsodbcsql-18.0.so.1.1
-rwxr-xr-x 1 root root 2076272 Feb  3 18:56 /opt/microsoft/msodbcsql18/lib64/libmsodbcsql-18.0.so.1.1

I have checked library dependencies (although I did have to CD to the actual directory the .so was in for LDD to work?)

/opt/microsoft/msodbcsql18/lib64#
ldd libmsodbcsql-18.0.so.1.1
linux-vdso.so.1 (0x00007ffe7516b000)
libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007f00bd286000)
librt.so.1 => /lib/x86_64-linux-gnu/librt.so.1 (0x00007f00bd07e000)
libodbcinst.so.2 => /usr/lib/x86_64-linux-gnu/libodbcinst.so.2 (0x00007f00bce63000)
libkrb5.so.3 => /usr/lib/x86_64-linux-gnu/libkrb5.so.3 (0x00007f00bcb8d000)
libgssapi_krb5.so.2 => /usr/lib/x86_64-linux-gnu/libgssapi_krb5.so.2 (0x00007f00bc942000)
libstdc++.so.6 => /usr/lib/x86_64-linux-gnu/libstdc++.so.6 (0x00007f00bc5b9000)
libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007f00bc21b000)
libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007f00bc003000)
libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007f00bbde4000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f00bb9f3000)
/lib64/ld-linux-x86-64.so.2 (0x00007f00bd899000)
libk5crypto.so.3 => /usr/lib/x86_64-linux-gnu/libk5crypto.so.3 (0x00007f00bb7c1000)
libcom_err.so.2 => /lib/x86_64-linux-gnu/libcom_err.so.2 (0x00007f00bb5bd000)
libkrb5support.so.0 => /usr/lib/x86_64-linux-gnu/libkrb5support.so.0 (0x00007f00bb3b2000)
libkeyutils.so.1 => /lib/x86_64-linux-gnu/libkeyutils.so.1 (0x00007f00bb1ae000)
libresolv.so.2 => /lib/x86_64-linux-gnu/libresolv.so.2 (0x00007f00baf94000)

These files exist:

/usr/lib/php/20190902/sqlsrv.so
/usr/lib/php/20190902/pdo_sqlsrv.so
/etc/php/7.4/mods-available/sqlsrv.ini
/etc/php/7.4/mods-available/pdo_sqlsrv.ini
/etc/odbc.ini
<empty>
/etc/odbcinst.ini
[ODBC Driver 18 for SQL Server]
Description=Microsoft ODBC Driver 18 for SQL Server
Driver=/opt/microsoft/msodbcsql18/lib64/libmsodbcsql-18.0.so.1.1
UsageCount=1
absci commented 2 years ago

Could you try connect with isql to verify if the driver is installed correctly, for example isql -v -k 'DRIVER=ODBC DRIVER 18 FOR SQL SERVER;SERVER=database.windows.net;uid=;pwd=;... ...'. You can modify the connection string after -k for your environment. If you still getting the same error, try strace isql -v -k ..., strace will give more information for debugging.

kosmic7 commented 2 years ago

Thanks for the help! I tried the ISQL command and it connects OK with no error.

kosmic7 commented 2 years ago

Oops did not mean to close this. Still looking high and low for an answer.

absci commented 2 years ago

Thanks for the help! I tried the ISQL command and it connects OK with no error.

So the ODBC driver is working. Could you post some sample php code that you used to connect? You can also strace php to get more debug info.

kosmic7 commented 2 years ago

Code I'm testing with is pretty basic:

$serverName = "xxxxx";
$connectionOptions = array(
    "database" => "xxxxx",
    "uid" => "xxxxx",
    "pwd" => "xxxxx",
    "TrustServerCertificate" => 1
);

$conn = sqlsrv_connect($serverName, $connectionOptions);
if ($conn === false) {
    die(print_r(sqlsrv_errors(), true));
}

Output: Array ( [0] => Array ( [0] => 01000 [SQLSTATE] => 01000 [1] => 0 [code] => 0 [2] => [unixODBC][Driver Manager]Can't open lib '/opt/microsoft/msodbcsql18/lib64/libmsodbcsql-18.0.so.1.1' : file not found [message] => [unixODBC][Driver Manager]Can't open lib '/opt/microsoft/msodbcsql18/lib64/libmsodbcsql-18.0.so.1.1' : file not found ) )

While trying the strace, I see that it's working OK from the command line. I am only getting the error when running it via the web server. So most likely an Nginx config issue?

Just in case it matters... Nginx on my server was already installed and configured for the site I'm working on and is a bit complex. I didn't see an easy way to add the below (from MS install doc) but assumed it was already in place since PHP is working fine.

# pass PHP scripts to FastCGI server
#
location ~ \.php$ {
        include snippets/fastcgi-php.conf;
        fastcgi_pass unix:/run/php/php7.4-fpm.sock;
}
kosmic7 commented 2 years ago

I tried enabling Trace in odbcinst.ini. I get results from that if I run my PHP code from the command line, but if I try in browser, nothing shows up in my trace file. For some reason it must not be seeing or using \etc\odbcinst.ini when running PHP on web server?

absci commented 2 years ago

I tried enabling Trace in odbcinst.ini. I get results from that if I run my PHP code from the command line, but if I try in browser, nothing shows up in my trace file. For some reason it must not be seeing or using \etc\odbcinst.ini when running PHP on web server?

Do you have multiple PHP versions installed on that machine? Possibly Nginx is not using the right version.

kosmic7 commented 2 years ago

Ah good idea there. I do have multiple versions of PHP installed. But running phpinfo() in browser is showing PHP version 7.4.29.

kosmic7 commented 2 years ago

Hey I'm going to close this issue. I never did find a fix. Must be something with how hosted server is preconfigured. I decided redoing my app to use web services would be a better way to go. Much thanks for trying @absci!

eleven-0325 commented 2 years ago

Make sure you are using bash or zsh if bash: echo 'export PATH="$PATH:/opt/mssql-tools18/bin"' >> ~/.bashrc source ~/.bashrc if zsh: echo 'export PATH="$PATH:/opt/mssql-tools18/bin"' >> ~/.zshrc source ~/.zshrc

and make sure the python>=3.10 (if use)

IHiJump commented 1 year ago

I ran into this issue and found that Net::FTP was causing the problem. If I comment out the Net::FTP and Net::SFTP use statements, it works fine.