msphpsql: Undefined function sqlsrv_connect() - Ubuntu 16.04

Hello,

I have problem with installing sqlsrv. I am using Ubuntu 16,04 and PHP v. 7.0. I went through the installation as you describing without problem, but with your test php file I am getting this error:

Fatal error: Uncaught Error: Call to undefined function sqlsrv_connect() in /var/www/html/web/testsql.php:17 Stack trace: #0 {main} thrown in /var/www/html/web/testsql.php on line 17

The only difference that I found is, that although I am using PHP 7.0 .so files are in 20160303 folder - I changed the lines in php.ini files, but it still doesnt work.

Could you please help me with this problem? Both php.ini are attached.

Thank you

D. Stanek

php_apache.txt php_cli.txt

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Comments: 44 (9 by maintainers)

Most upvoted comments

The set up guide needs updating. I managed to get it working on CLI and apache by adding the following lines: extension=sqlsrv.so

to

/etc/php/7.0/cli/php.ini

and

/etc/php/7.0/apache2/php.ini

@stanedav I went through the log you sent and did the exact steps, but I was unable to get apache run php7.0 and commandline use php 7.1, assuming that php 7.1 is what we want to run on apache, let’s clean up php7.0 dependencies that might be installed from php 7.0 installation

1. Clean up
sudo su
apt-get purge libapache2-mod-php7.0
apt-get purge apache2
apt-get purge php.7.0
apt autoremove php7.0-fpm
1. install PHP 7.1
sudo su
add-apt-repository ppa:ondrej/php
apt-get update
apt-get -y install php7.1 mcrypt php7.1-mcrypt php-mbstring php-pear php7.1-dev 
1. install apache and PHP 7.1 apache module
sudo apt-get install libapache2-mod-php7.1 
sudo apt-get install apache2
1. Configure ini
echo "extension=/usr/lib/php/20160303/sqlsrv.so" >> /etc/php/7.1/apache2/php.ini
echo "extension=/usr/lib/php/20160303/sqlsrv.so" >> /etc/php/7.1/cli/php.ini
1. restart apache
sudo service apache2 restart

Thank a lot. It helped me as well

arrrr! @yitam thanks. Sorry for the stupid question!

Hello guys, pretty rich conversation here, I tried updated readme, then added extension=sqlsrv.so to both ini files and now it works! Thanks for your effort!

@meet-bhagdev Yes, that’s how I solved it. I set up a fresh Ubuntu VirtualBox/Vagrant installation and was trying to solve this issue. Adding the extension in the format mentioned fixed it for my installation, and it seems to be working great now. I am actually NOT the OP, but I was having the same issue so I figured I’d post how I fixed it. FWIW I installed every php extension I could find.

@stanedav I went through the log you sent and did the exact steps, but I was unable to get apache run php7.0 and commandline use php 7.1, assuming that php 7.1 is what we want to run on apache, let’s clean up php7.0 dependencies that might be installed from php 7.0 installation

  1. Clean up
sudo su
apt-get purge libapache2-mod-php7.0
apt-get purge apache2
apt-get purge php.7.0
apt autoremove php7.0-fpm
  1. install PHP 7.1
sudo su
add-apt-repository ppa:ondrej/php
apt-get update
apt-get -y install php7.1 mcrypt php7.1-mcrypt php-mbstring php-pear php7.1-dev 
  1. install apache and PHP 7.1 apache module
sudo apt-get install libapache2-mod-php7.1 
sudo apt-get install apache2
  1. Configure ini
echo "extension=/usr/lib/php/20160303/sqlsrv.so" >> /etc/php/7.1/apache2/php.ini
echo "extension=/usr/lib/php/20160303/sqlsrv.so" >> /etc/php/7.1/cli/php.ini
  1. restart apache
sudo service apache2 restart

this is output of edited .php file, you will find it in attachment. testsql.txt

Yes, I have multiple installations, because before I found this GitHub I found many guides how to install sqlsrv and it needed php 5.6… If I list my /etc/php there are three folders: 5.6 7.0 7.1,…

I am wondering, I dont have any data on my server, and I already set up SSH, maybe I can send you credentials via PM?