2

I am trying to enable sqlsrv drivers for php8.1 on Ubuntu 20.0. It is not showing the extension in phpinfo().

When trying to check the sqlsrv module with commmand php -m, the output is like this:

enter image description here

I have followed official documentation below:

I am not sure what went wrong, any suggestion is appreciated.

The output of phpinfo() for php7.4:

List item

The output of phpinfo() for php8.1:

enter image description here

Here are the things:

  • PHP 7.4 and 8.1 installed on my machine.
  • The sqlsrv drivers works fine for php7.4 version
  • When trying to install/enable for php8.1 it does not work at all.

What I am missing here?

Hemant Kumar
  • 1,025
  • 15
  • 32

2 Answers2

2

You can try this:

1. switch to php8.1
2. sudo pecl uninstall -r sqlsrv 
3. sudo pecl uninstall -r pdo_sqlsrv 
4. sudo pecl -d php_suffix=7.2 install sqlsrv
5. sudo pecl -d php_suffix=7.2 install pdo_sqlsrv
6. sudo service apache2 restart

Note that -r, --register-only do not remove files but only register the packages as not installed.

Checkout this resource for more info. https://github.com/microsoft/msphpsql/issues/1145#issuecomment-649682231

Prawal
  • 58
  • 6
0

I was able to fix this by adding below commands.

pecl install sqlsrv pdo_sqlsrv
printf "; priority=20\nextension=sqlsrv.so\n" > /etc/php/8.1/mods-available/sqlsrv.ini
printf "; priority=30\nextension=pdo_sqlsrv.so\n" > /etc/php/8.1/mods-available/pdo_sqlsrv.ini
phpenmod -v 8.1 sqlsrv pdo_sqlsrv

after that need to restart apache2

Hasitha
  • 738
  • 8
  • 16