Install/enable php8.1's sqlsrv and pdo_sqlsrv drivers on ubuntu20.0
P粉501683874
P粉501683874 2023-11-01 11:06:13
0
2
973

I'm trying to enable the sqlsrv driver for php8.1 on Ubuntu 20.0. It doesn't show the extension in phpinfo().

When trying to check the sqlsrv module using the command php -m, the output is as follows:

I followed the following official documentation:

  • https://learn.microsoft.com/en-us/sql/connect/php/installation-tutorial-linux-mac?view=sql-server-ver16
  • Try to add extensions in /etc/php/8.1/apache2/php.ini (extension=pdo_sqlsrv.so, extension=sqlsrv.so)

I'm not sure what's going wrong, any suggestions would be appreciated.

The output of phpinfo() for php7.4:
The output of phpinfo() for php8.1:

The thing is like this:

  • I have PHP 7.4 and 8.1 installed on my computer.
  • sqlsrv driver is suitable for php7.4 version
  • When trying to install/enable php8.1 it doesn't work at all.

What am I missing here?

P粉501683874
P粉501683874

reply all(2)
P粉823268006

I was able to solve this problem by adding the following 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

You need to restart apache2 afterward

P粉193307465

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

Please note that -r, --register-only will not delete the file, but will only register the package as not installed.

Check out this resource for more information. https://github.com/microsoft/msphpsql/issues/1145#issuecomment- 649682231

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template