Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PHP Warning: PHP Startup: Unable to load dynamic library 'sqlsrv.so' & 'pdo_sqlsrv.so' #1145

Closed
conandrum opened this issue Jun 23, 2020 · 33 comments

Comments

@conandrum
Copy link

Hi,
I wanted to be able to access SQL Server from Ubuntu 18.04, so I followed this procedure:

sudo su
curl https://packages.microsoft.com/keys/microsoft.asc | apt-key add -

#Download appropriate package for the OS version - Ubuntu 18.04
curl https://packages.microsoft.com/config/ubuntu/18.04/prod.list > /etc/apt/sources.list.d/mssql-release.list
exit
sudo apt-get update
sudo ACCEPT_EULA=Y apt-get install msodbcsql17

# optional: for bcp and sqlcmd
sudo ACCEPT_EULA=Y apt-get install mssql-tools
echo 'export PATH="$PATH:/opt/mssql-tools/bin"' >> ~/.bash_profile
echo 'export PATH="$PATH:/opt/mssql-tools/bin"' >> ~/.bashrc
source ~/.bashrc
# optional: for unixODBC development headers
sudo apt-get install unixodbc-dev

# I did not run the following line
# sudo apt-get -y install php-pear php7.2-dev

sudo pecl install sqlsrv
sudo pecl install pdo_sqlsrv
sudo su
printf "; priority=20\nextension=sqlsrv.so\n" > /etc/php/7.2/mods-available/sqlsrv.ini
printf "; priority=30\nextension=pdo_sqlsrv.so\n" > /etc/php/7.2/mods-available/pdo_sqlsrv.ini
printf "; priority=20\nextension=sqlsrv.so\n" > /etc/php/7.3/mods-available/sqlsrv.ini
printf "; priority=30\nextension=pdo_sqlsrv.so\n" > /etc/php/7.3/mods-available/pdo_sqlsrv.ini
printf "; priority=20\nextension=sqlsrv.so\n" > /etc/php/7.4/mods-available/sqlsrv.ini
printf "; priority=30\nextension=pdo_sqlsrv.so\n" > /etc/php/7.4/mods-available/pdo_sqlsrv.ini
exit

sudo phpenmod sqlsrv pdo_sqlsrv
sudo service apache2 restart

I got only warnings with sudo pecl install pdo_sqlsrv & pdo_sqlsrv :

Notice: Trying to access array offset on value of type bool in PEAR/REST.php on line 187
PHP Notice:  Trying to access array offset on value of type bool in /usr/share/php/PEAR/REST.php on line 187

Notice: Trying to access array offset on value of type bool in PEAR/REST.php on line 187
PHP Notice:  Trying to access array offset on value of type bool in /usr/share/php/PEAR/REST.php on line 187

Notice: Trying to access array offset on value of type bool in PEAR/REST.php on line 187
PHP Notice:  Trying to access array offset on value of type bool in /usr/share/php/PEAR/REST.php on line 187

Notice: Trying to access array offset on value of type bool in PEAR/REST.php on line 187
PHP Notice:  Trying to access array offset on value of type bool in /usr/share/php/PEAR/REST.php on line 187
WARNING: channel "pecl.php.net" has updated its protocols, use "pecl channel-update pecl.php.net" to update

I did not try to rectify the above notices....
No errors were reported, so I thought all was ok, until I ran 'php -v' which gives me:

PHP Warning:  PHP Startup: Unable to load dynamic library 'sqlsrv.so' (tried: /usr/lib/php/20190902/sqlsrv.so (/usr/lib/php/20190902/sqlsrv.so: cannot open shared object file: No such file or directory), /usr/lib/php/20190902/sqlsrv.so.so (/usr/lib/php/20190902/sqlsrv.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0
PHP Warning:  PHP Startup: Unable to load dynamic library 'pdo_sqlsrv.so' (tried: /usr/lib/php/20190902/pdo_sqlsrv.so (/usr/lib/php/20190902/pdo_sqlsrv.so: cannot open shared object file: No such file or directory), /usr/lib/php/20190902/pdo_sqlsrv.so.so (/usr/lib/php/20190902/pdo_sqlsrv.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0
PHP 7.4.7 (cli) (built: Jun 12 2020 07:44:05) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
    with Zend OPcache v7.4.7, Copyright (c), by Zend Technologies

I have checked '/usr/lib/php/20190902/' which indeed does not contain these files.
They are actually in '/usr/lib/php/20170718/'

What did I do wrong in the installation? How do I fix this?

Thanks for your help people.

@yitam
Copy link
Contributor

yitam commented Jun 23, 2020

@conandrum you're using multiple php versions, and which php version do you want?

If you want php 7.4 only, please uninstall the others and follow the online instructions

If you want to keep more than one php version, please check how to switch between multiple php versions in Ubuntu

This related issue #1142 might give you some ideas, or please check this WIKI entry

@conandrum
Copy link
Author

This is a development server, multiple PHP versions are required to test various software. I want all versions.
I can switch easily between versions using virtualmin.

My issue has to do with the linkage of the plugins sqlsrv.so & pdo_sqlsrv.so.
They have been installed in the wrong folder, or are being referenced wrongly.
Can someone shed some light ?

@conandrum
Copy link
Author

Thanks for your link... I am reading it.

@conandrum
Copy link
Author

Hi Yitam,
I have checked the article but still not sure what exactly is wrong in my install procedure.
I assume that the 7.2 version of the driver has been installed due to the path where the pdo_sqlsrv.so & sqlsrv.so files have been placed.
I assume that there is an entry somewhere pointing to the 7.4 version of the path where the files are expected to be (but are not found).
What I do not understand is this:

  1. How should I have correctly installed these drivers for MULTIPLE PHP versions?

@yitam
Copy link
Contributor

yitam commented Jun 23, 2020

Yes @conandrum the key is to use update-alternatives as explained in how to switch between multiple php versions in Ubuntu. Every time you use pecl install sqlsrv drivers please do the following first, for each php version. For example, for php 7.4, just replace 7.3 with 7.4

sudo update-alternatives --set php /usr/bin/php7.3
sudo update-alternatives --set phar /usr/bin/phar7.3
sudo update-alternatives --set phar.phar /usr/bin/phar.phar7.3
sudo update-alternatives --set phpize /usr/bin/phpize7.3
sudo update-alternatives --set php-config /usr/bin/php-config7.3

Also, with sudo phpenmod and a2enmod you have to specify the php version too, like this sudo phpenmod -v 7.4 sqlsrv pdo_sqlsrv.

For details please follow the online instructions

@conandrum
Copy link
Author

@yitam what would you suggest I do to remedy the situation now?
Should I try to completely uninstall everything and start over, or try something else?

@yitam
Copy link
Contributor

yitam commented Jun 23, 2020

@conandrum I suppose you don't have to uninstall the php versions, and you probably have php 7.2 set up already.

Make sure you use update-alternatives as mentioned above before sudo pecl install sqlsrv and sudo pecl install pdo_sqlsrv. Please follow our online instructions for php 7.4 (see above).

If it works for php 7.4 then you can try 7.3 etc. Whenever you switch php version from one to another, just use update-alternatives again.

@conandrum
Copy link
Author

@yitam I just started with the mods you suggested. I started with this:

php -v
PHP 7.4.7 (cli) (built: Jun 12 2020 07:44:05) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
with Zend OPcache v7.4.7, Copyright (c), by Zend Technologies

sudo update-alternatives --set php /usr/bin/php7.4
sudo update-alternatives --set phar /usr/bin/phar7.4
sudo update-alternatives --set phar.phar /usr/bin/phar.phar7.4
sudo update-alternatives --set phpize /usr/bin/phpize7.4
sudo update-alternatives --set php-config /usr/bin/php-config7.4
sudo pecl install sqlsrv

This is the weird part.
Towards the end of the output of the last command I see this "20170718":

running: make INSTALL_ROOT="/tmp/pear/temp/pear-build-rootRBWguk/install-sqlsrv-5.8.1" install
Installing shared extensions:     /tmp/pear/temp/pear-build-rootRBWguk/install-sqlsrv-5.8.1/usr/lib/php/20170718/
running: find "/tmp/pear/temp/pear-build-rootRBWguk/install-sqlsrv-5.8.1" | xargs ls -dils
147596   4 drwxr-xr-x 3 root root   4096 Jun 24 06:17 /tmp/pear/temp/pear-build-rootRBWguk/install-sqlsrv-5.8.1
147602   4 drwxr-xr-x 3 root root   4096 Jun 24 06:17 /tmp/pear/temp/pear-build-rootRBWguk/install-sqlsrv-5.8.1/usr
147603   4 drwxr-xr-x 3 root root   4096 Jun 24 06:17 /tmp/pear/temp/pear-build-rootRBWguk/install-sqlsrv-5.8.1/usr/lib
147604   4 drwxr-xr-x 3 root root   4096 Jun 24 06:17 /tmp/pear/temp/pear-build-rootRBWguk/install-sqlsrv-5.8.1/usr/lib/php
147605   4 drwxr-xr-x 2 root root   4096 Jun 24 06:17 /tmp/pear/temp/pear-build-rootRBWguk/install-sqlsrv-5.8.1/usr/lib/php/20170718
 25431 380 -rwxr-xr-x 1 root root 386336 Jun 24 06:17 /tmp/pear/temp/pear-build-rootRBWguk/install-sqlsrv-5.8.1/usr/lib/php/20170718/sqlsrv.so

Build process completed successfully
Installing '/usr/lib/php/20170718/sqlsrv.so'
install ok: channel://pecl.php.net/sqlsrv-5.8.1
configuration option "php_ini" is not set to php.ini location
You should add "extension=sqlsrv.so" to php.ini

Shouldn't it pick up the right folder for php7.4 automatically?
I did not proceed any further until I had spoken with you about it.

@conandrum
Copy link
Author

@yitam I did one more test. I run
sudo pecl uninstall sqlsrv
This time, I installed also the
sudo apt-get -y install php7.4-dev
Then again:
sudo pecl install sqlsrv

Success with paths showing 20190902:

Installing shared extensions:     /tmp/pear/temp/pear-build-root6qqGUU/install-sqlsrv-5.8.1/usr/lib/php/20190902/
running: find "/tmp/pear/temp/pear-build-root6qqGUU/install-sqlsrv-5.8.1" | xargs ls -dils
147600   4 drwxr-xr-x 3 root root   4096 Jun 24 06:42 /tmp/pear/temp/pear-build-root6qqGUU/install-sqlsrv-5.8.1
147606   4 drwxr-xr-x 3 root root   4096 Jun 24 06:42 /tmp/pear/temp/pear-build-root6qqGUU/install-sqlsrv-5.8.1/usr
147607   4 drwxr-xr-x 3 root root   4096 Jun 24 06:42 /tmp/pear/temp/pear-build-root6qqGUU/install-sqlsrv-5.8.1/usr/lib
147608   4 drwxr-xr-x 3 root root   4096 Jun 24 06:42 /tmp/pear/temp/pear-build-root6qqGUU/install-sqlsrv-5.8.1/usr/lib/php
147609   4 drwxr-xr-x 2 root root   4096 Jun 24 06:42 /tmp/pear/temp/pear-build-root6qqGUU/install-sqlsrv-5.8.1/usr/lib/php/20190902
 49484 380 -rwxr-xr-x 1 root root 385528 Jun 24 06:42 /tmp/pear/temp/pear-build-root6qqGUU/install-sqlsrv-5.8.1/usr/lib/php/20190902/sqlsrv.so

Build process completed successfully
Installing '/usr/lib/php/20190902/sqlsrv.so'
install ok: channel://pecl.php.net/sqlsrv-5.8.1
configuration option "php_ini" is not set to php.ini location
You should add "extension=sqlsrv.so" to php.ini

I will continue and report back

@conandrum
Copy link
Author

@yitam After completing all the steps below specific to 7.4, I can confirm that no errors are being reported when running php -v

sudo apt-get -y install php-pear php7.4-dev

sudo update-alternatives --set php /usr/bin/php7.4
sudo update-alternatives --set phar /usr/bin/phar7.4
sudo update-alternatives --set phar.phar /usr/bin/phar.phar7.4
sudo update-alternatives --set phpize /usr/bin/phpize7.4
sudo update-alternatives --set php-config /usr/bin/php-config7.4

sudo pecl install sqlsrv
sudo pecl install pdo_sqlsrv
sudo su
printf "; priority=20\nextension=sqlsrv.so\n" > /etc/php/7.4/mods-available/sqlsrv.ini
printf "; priority=30\nextension=pdo_sqlsrv.so\n" > /etc/php/7.4/mods-available/pdo_sqlsrv.ini
exit
sudo phpenmod -v 7.4 sqlsrv pdo_sqlsrv
sudo service apache2 restart

@conandrum
Copy link
Author

conandrum commented Jun 24, 2020

@yitam Then I went on to install the plugins onto 7.3 & 7.2
Problem:
When I switch to other versions and do php -v I get the usual notices as in initial post:

PHP Warning:  PHP Startup: Unable to load dynamic library 'sqlsrv.so' (tried: /usr/lib/php/xxxxxxxx/sqlsrv.so (/usr/lib/php/xxxxxxxx/sqlsrv.so: cannot open shared object file: No such file or directory), /usr/lib/php/xxxxxxxx/sqlsrv.so.so (/usr/lib/php/xxxxxxxx/sqlsrv.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0
PHP Warning:  PHP Startup: Unable to load dynamic library 'pdo_sqlsrv.so' (tried: /usr/lib/php/xxxxxxxx/pdo_sqlsrv.so (/usr/lib/php/xxxxxxxx/pdo_sqlsrv.so: cannot open shared object file: No such file or directory), /usr/lib/php/xxxxxxxx/pdo_sqlsrv.so.so (/usr/lib/php/xxxxxxxx/pdo_sqlsrv.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0

If I then just try to install with:
sudo pecl install sqlsrv
I get:

 sudo pecl install sqlsrv
PHP Warning:  PHP Startup: Unable to load dynamic library 'sqlsrv.so' (tried: /usr/lib/php/xxxxxxxx/sqlsrv.so (/usr/lib/php/xxxxxxxx/sqlsrv.so: cannot open shared object file: No such file or directory), /usr/lib/php/xxxxxxxx/sqlsrv.so.so (/usr/lib/php/xxxxxxxx/sqlsrv.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0
PHP Warning:  PHP Startup: Unable to load dynamic library 'pdo_sqlsrv.so' (tried: /usr/lib/php/xxxxxxxx/pdo_sqlsrv.so (/usr/lib/php/xxxxxxxx/pdo_sqlsrv.so: cannot open shared object file: No such file or directory), /usr/lib/php/xxxxxxxx/pdo_sqlsrv.so.so (/usr/lib/php/xxxxxxxx/pdo_sqlsrv.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0
pecl/sqlsrv is already installed and is the same as the released version 5.8.1
install failed

If I uninstall first using:

sudo pecl uninstall sqlsrv
sudo pecl install sqlsrv

then all goes well, but the previous 7.4 installation is now broken.
Catch 22.

How do I install this on multiple php versions? Do I just manually copy the files from their location to /usr/lib/php/xxxxxxxx ???

@yitam
Copy link
Contributor

yitam commented Jun 24, 2020

@conandrum did you do update-alternatives before installing drivers for 7.3 or 7.2?

Have you read the FAQ entry I sent you earlier on using pecl or php-config? Before you install make sure you're using the right php version. You also need php7.3-dev and php7.2-dev too

@conandrum
Copy link
Author

@yitam
did you do update-alternatives before installing drivers for 7.3 or 7.2?
Yes! as seen here: #1145 (comment)

Have you read the FAQ entry I sent you earlier on using pecl or php-config?
Yes!

Before you install make sure you're using the right php version.
Yes. I always do update-alternatives before installing drivers.

You also need php7.3-dev and php7.2-dev too
Yes. I did install those too before installing drivers.

This is the problem:
I install the drivers for 7.4 (for example) and all is OK.
Then I switch version to 7.3 with update-alternatives.
Then I try to install sudo pecl install sqlsrv
I get this:

PHP Warning:  PHP Startup: Unable to load dynamic library 'sqlsrv.so' (tried: /usr/lib/php/xxxxxxxx/sqlsrv.so (/usr/lib/php/xxxxxxxx/sqlsrv.so: cannot open shared object file: No such file or directory), /usr/lib/php/xxxxxxxx/sqlsrv.so.so (/usr/lib/php/xxxxxxxx/sqlsrv.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0
PHP Warning:  PHP Startup: Unable to load dynamic library 'pdo_sqlsrv.so' (tried: /usr/lib/php/xxxxxxxx/pdo_sqlsrv.so (/usr/lib/php/xxxxxxxx/pdo_sqlsrv.so: cannot open shared object file: No such file or directory), /usr/lib/php/xxxxxxxx/pdo_sqlsrv.so.so (/usr/lib/php/xxxxxxxx/pdo_sqlsrv.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0
pecl/sqlsrv is already installed and is the same as the released version 5.8.1
install failed

The driver does not understand that I need the 7.3 version ON TOP of the 7.4 already installed !!!!!
It's all in my last post #1145 (comment)

@yitam
Copy link
Contributor

yitam commented Jun 25, 2020

Hi @conandrum

In addition to using update-alternatives, I realized that you need to do the following too:

1. sudo pecl uninstall -r sqlsrv 
2. sudo pecl uninstall -r pdo_sqlsrv 
3. sudo pecl -d php_suffix=7.2 install sqlsrv
4. sudo pecl -d php_suffix=7.2 install pdo_sqlsrv

Note that -r, --register-only do not remove files but only register the packages as not installed.
Then repeat the above steps for the other php versions.

I did a quick test myself and was able to install sqlsrv with all php versions:

image

Using update-alternatives is the key to switch between php versions.

@conandrum
Copy link
Author

HI @yitam, that's excellent news.
I will try it and let you know.

@conandrum
Copy link
Author

conandrum commented Jul 5, 2020

and yes it works my friend. Thank you. Here is the full sqlsrv & pdo_sqlsrv install script for multiple php versions.

# Microsoft ODBC 17
sudo su
curl https://packages.microsoft.com/keys/microsoft.asc | apt-key add -

#Download appropriate package for the OS version - Ubuntu 18.04
curl https://packages.microsoft.com/config/ubuntu/18.04/prod.list > /etc/apt/sources.list.d/mssql-release.list
exit
sudo apt-get update
sudo ACCEPT_EULA=Y apt-get install msodbcsql17

# optional: for bcp and sqlcmd
sudo ACCEPT_EULA=Y apt-get install mssql-tools
echo 'export PATH="$PATH:/opt/mssql-tools/bin"' >> ~/.bash_profile
echo 'export PATH="$PATH:/opt/mssql-tools/bin"' >> ~/.bashrc
source ~/.bashrc
# optional: for unixODBC development headers
sudo apt-get install unixodbc-dev

# Microsoft ODBC 17
# 7.4
sudo apt-get -y install php-pear php7.4-dev
sudo update-alternatives --set php /usr/bin/php7.4
sudo update-alternatives --set phar /usr/bin/phar7.4
sudo update-alternatives --set phar.phar /usr/bin/phar.phar7.4
sudo update-alternatives --set phpize /usr/bin/phpize7.4
sudo update-alternatives --set php-config /usr/bin/php-config7.4

sudo pecl uninstall -r sqlsrv 
sudo pecl uninstall -r pdo_sqlsrv 
sudo pecl -d php_suffix=7.4 install sqlsrv
sudo pecl -d php_suffix=7.4 install pdo_sqlsrv
sudo su
printf "; priority=20\nextension=sqlsrv.so\n" > /etc/php/7.4/mods-available/sqlsrv.ini
printf "; priority=30\nextension=pdo_sqlsrv.so\n" > /etc/php/7.4/mods-available/pdo_sqlsrv.ini
exit
sudo phpenmod -v 7.4 sqlsrv pdo_sqlsrv
sudo service apache2 restart


# 7.3
sudo apt-get -y install php-pear php7.3-dev
sudo update-alternatives --set php /usr/bin/php7.3
sudo update-alternatives --set phar /usr/bin/phar7.3
sudo update-alternatives --set phar.phar /usr/bin/phar.phar7.3
sudo update-alternatives --set phpize /usr/bin/phpize7.3
sudo update-alternatives --set php-config /usr/bin/php-config7.3

sudo pecl uninstall -r sqlsrv 
sudo pecl uninstall -r pdo_sqlsrv 
sudo pecl -d php_suffix=7.3 install sqlsrv
sudo pecl -d php_suffix=7.3 install pdo_sqlsrv
sudo su
printf "; priority=20\nextension=sqlsrv.so\n" > /etc/php/7.3/mods-available/sqlsrv.ini
printf "; priority=30\nextension=pdo_sqlsrv.so\n" > /etc/php/7.3/mods-available/pdo_sqlsrv.ini
exit
sudo phpenmod -v 7.3 sqlsrv pdo_sqlsrv
sudo service apache2 restart

# 7.2
sudo apt-get -y install php-pear php7.2-dev
sudo update-alternatives --set php /usr/bin/php7.2
sudo update-alternatives --set phar /usr/bin/phar7.2
sudo update-alternatives --set phar.phar /usr/bin/phar.phar7.2
sudo update-alternatives --set phpize /usr/bin/phpize7.2
sudo update-alternatives --set php-config /usr/bin/php-config7.2

sudo pecl uninstall -r sqlsrv 
sudo pecl uninstall -r pdo_sqlsrv 
sudo pecl -d php_suffix=7.2 install sqlsrv
sudo pecl -d php_suffix=7.2 install pdo_sqlsrv
sudo su
printf "; priority=20\nextension=sqlsrv.so\n" > /etc/php/7.2/mods-available/sqlsrv.ini
printf "; priority=30\nextension=pdo_sqlsrv.so\n" > /etc/php/7.2/mods-available/pdo_sqlsrv.ini
exit
sudo phpenmod -v 7.2 sqlsrv pdo_sqlsrv
sudo service apache2 restart


@yitam
Copy link
Contributor

yitam commented Jul 6, 2020

That's great, @conandrum . I will link your above script to the FAQ entry and close this issue. Please feel free to reopen if necessary.

@yitam yitam closed this as completed Jul 6, 2020
@conandrum
Copy link
Author

conandrum commented Oct 22, 2020

One more question.
My Installed version | 17.5.2.1-1
Available version | 17.6.1.1-1

How do I go about updating my multiple versions properly?
Should I run the above script again from the beginning?

@yitam
Copy link
Contributor

yitam commented Oct 22, 2020

hi @conandrum , to upgrade ODBC driver and tools in Ubuntu please follow the instructions

@conandrum
Copy link
Author

This is Ubuntu 18.04

@yitam
Copy link
Contributor

yitam commented Oct 22, 2020

My bad. I've modified the comment above.

@conandrum
Copy link
Author

conandrum commented Oct 22, 2020

So basically I run everything in the above script until line #18 (up to and including 'sudo apt-get install unixodbc-dev')
Now the msodbcsql17 package is up to date:

# apt-show-versions msodbcsql17
msodbcsql17:amd64/bionic 17.6.1.1-1 uptodate

The rest of the script from line #19 down is not required to be run again for each version of PHP?

@yitam
Copy link
Contributor

yitam commented Oct 22, 2020

It depends, @conandrum . If you want the latest updates for each PHP version then please update only the PHP packages.

If you do not purge the packages, technically you should not need to pecl install sqlsrv or pdo_sqlsrv drivers again. The last stable release 5.8.1 for sqlsrv drivers should work with the latest PHP versions.

If you prefer a clean start, then you might do the following steps (I picked 7.3 as an example):

    sudo apt-get purge php7.3 php7.3-dev php7.3-xml php7.3-common -y --allow-unauthenticated
 
    sudo apt-get update
    sudo apt-get autoremove -y
    sudo apt-get autoclean -y

@conandrum
Copy link
Author

As an example, my PHP 7.3 contains the following relevant packages pdo_sqlsrv & sqlsrv (among others)
After upgrading ODBC driver and tools (using the above script until line #18 ), PHP can access MS SQL just fine.

The pdo_sqlsrv & sqlsrv modules are developed by Microsoft here https://github.com/Microsoft/msphpsql/releases/tag/v5.8.0 under your supervision.
From what I can understand, these PHP drivers, support certain ODBC driver versions, and at some point in time the ODBC driver will not be compatible with some old version of the PHP drivers. Correct?

So to ensure pdo_sqlsrv & sqlsrv remain up to date what commands should I run?

@yitam
Copy link
Contributor

yitam commented Oct 23, 2020

@conandrum you can check the system requirements page and watch this msphpsql repo for releases only.

Alternatively, you may want to check the PHP updates on the Microsoft Tech community blog. Hope this helps!

@GlistenSTAR
Copy link

GlistenSTAR commented May 4, 2021

hello, yitam, I wanna close this message,

PHP Warning: PHP Startup: Unable to load dynamic library 'sqlsrv.so' (tried: /usr/lib/php/20180731/sqlsrv.so (/usr/lib/php/20180731/sqlsrv.so: cannot open shared object file: No such file or directory), /usr/lib/php/20180731/sqlsrv.so.so (/usr/lib/php/20180731/sqlsrv.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0
PHP Warning: PHP Startup: Unable to load dynamic library 'pdo_sqlsrv.so' (tried: /usr/lib/php/20180731/pdo_sqlsrv.so (/usr/lib/php/20180731/pdo_sqlsrv.so: cannot open shared object file: No such file or directory), /usr/lib/php/20180731/pdo_sqlsrv.so.so (/usr/lib/php/20180731/pdo_sqlsrv.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0
PHP 7.3.28-1+ubuntu20.04.1+deb.sury.org+1 (cli) (built: May 1 2021 11:54:39) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.3.28, Copyright (c) 1998-2018 Zend Technologies
with Zend OPcache v7.3.28-1+ubuntu20.04.1+deb.sury.org+1, Copyright (c) 1999-2018, by Zend Technologies

image

As you can see, I input command "php-cli"

At first I wanna install ms-sql. So I had done several step on several article.
but I will give up local mssql db, how can I delete this message.

@yitam
Copy link
Contributor

yitam commented May 4, 2021

Hi @GlistenSTAR

You should be able to use phpdismod

For example,

sudo phpdismod -v 7.3 sqlsrv pdo_sqlsrv

@GlistenSTAR
Copy link

Wonderful, you are perfect on this area.
Thank your reply.

@conandrum
Copy link
Author

conandrum commented Jan 26, 2022 via email

@yitam
Copy link
Contributor

yitam commented Jan 26, 2022

Hi @conandrum, ODBC driver might still work. A quick way to check using isql is shown below:

isql -v -k "Driver=ODBC Driver 17 for SQL Server;server=<yourserver>;uid=<yourid>;pwd=<yourpswd>"

You may also run some quick tests with your php apps.

If in doubt, you can uninstall (sudo apt-get purge -y msodbcsql17 mssql-tools) and install ODBC driver again by following the online instructions

@conandrum
Copy link
Author

conandrum commented Jan 26, 2022

Hey Yitam. I was asking specifically what I should do with the contents of the file mssql-release.list.
Shouldn't I uncomment the line below, and convert it to point to the 'focal' source?
# deb [arch=amd64] https://packages.microsoft.com/ubuntu/18.04/prod bionic main

@yitam
Copy link
Contributor

yitam commented Jan 27, 2022

You don't have to do anything if your ODBC driver is already working. If you like, you can simply replace it with the one for Ubuntu 20.04 as shown in the aforementioned ODBC online instructions

@8brothers
Copy link

Hi @conandrum

In addition to using update-alternatives, I realized that you need to do the following too:

1. sudo pecl uninstall -r sqlsrv 
2. sudo pecl uninstall -r pdo_sqlsrv 
3. sudo pecl -d php_suffix=7.2 install sqlsrv
4. sudo pecl -d php_suffix=7.2 install pdo_sqlsrv

Note that -r, --register-only do not remove files but only register the packages as not installed. Then repeat the above steps for the other php versions.

I did a quick test myself and was able to install sqlsrv with all php versions:

image

Using update-alternatives is the key to switch between php versions.

I have same issue and asked question on stackoverflow with all the details but this solution work for me.
Link for question on stack:
https://stackoverflow.com/questions/74422334/install-enable-sqlsrv-pdo-sqlsrv-drivers-for-php8-1-on-ubuntu20-0?noredirect=1

Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants