Search code examples
phpsql-serversqlsrvphp-8.1

Install/enable sqlsrv & pdo_sqlsrv drivers for php8.1 on ubuntu20.0


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?


Solution

  • 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