msphpsql: PHP Warning: PHP Startup: Unable to load dynamic library 'sqlsrv.so' & 'pdo_sqlsrv.so'
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.
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Comments: 33 (13 by maintainers)
and yes it works my friend. Thank you. Here is the full sqlsrv & pdo_sqlsrv install script for multiple php versions.
Hi @conandrum
In addition to using update-alternatives, I realized that you need to do the following too:
Note that
-r, --register-onlydo 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:
Using update-alternatives is the key to switch between php versions.
Hi @GlistenSTAR
You should be able to use phpdismod
For example,
@yitam After completing all the steps below specific to 7.4, I can confirm that no errors are being reported when running php -v
Wonderful, you are perfect on this area. Thank your reply.
@yitam I did one more test. I run
sudo pecl uninstall sqlsrvThis time, I installed also thesudo apt-get -y install php7.4-devThen again:sudo pecl install sqlsrvSuccess with paths showing 20190902:
I will continue and report back
@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