Skip to content
Advertisement

Installing pdo_sqlsrv driver in PHP 7.4 using CentOS 8

I have successfully installed php 7.4 with Remi packages in my CentOS 8 VPS (Used this guide https://www.digitalocean.com/community/tutorials/how-to-run-multiple-php-versions-on-one-server-using-apache-and-php-fpm-on-centos-8)

I have a VirtualHost in my Apache server, that points to my domain and load the required php version for that environment.

<VirtualHost *:80>
    ServerName www.example.net
    ServerAlias example.net
    DocumentRoot /var/www/example.net/html
    ErrorLog /var/www/example.net/log/error.log
    CustomLog /var/www/example.net/log/requests.log combined
  <IfModule !mod_php7.c>
    <FilesMatch .(php|phar)$>
        SetHandler "proxy:unix:/var/opt/remi/php74/run/php-fpm/www.sock|fcgi://localhost"
    </FilesMatch>
  </IfModule>
</VirtualHost>

How do you enable the pdo_sqlsrv extension to a php 7.4 installation using Remi?

I’ve followed this guide: https://learn.microsoft.com/en-us/sql/connect/php/installation-tutorial-linux-mac?view=sql-server-ver15#installing-the-drivers-on-red-hat-7-and-8 but I think something went wrong.

If I do <?php echo phpinfo(); ?> I see that no modules are being loaded https://gyazo.com/d5a30969f06c49e78bf3473a07776492

Also if I check for the PHP version using php -v, this is the output:

PHP Warning:  Module 'sqlsrv' already loaded in Unknown on line 0
PHP Warning:  Module 'pdo_sqlsrv' already loaded in Unknown on line 0
PHP 7.4.12 (cli) (built: Oct 27 2020 15:01:52) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies

EDIT:

I have also checked using this command yum list installed | grep php

and I have the following output. Notice the php-pdo from remi.

php-json.x86_64                     7.4.12-1.el8.remi                          @remi-modular
php-pdo.x86_64                      7.4.12-1.el8.remi                          @remi-modular
php-sqlsrv.x86_64                   5.8.1-1.el8.remi.7.4                       @remi-modular
php74.x86_64                        1.0-3.el8.remi                             @remi-safe
php74-php-cli.x86_64                7.4.12-1.el8.remi                          @remi-safe
php74-php-common.x86_64             7.4.12-1.el8.remi                          @remi-safe
php74-php-fpm.x86_64                7.4.12-1.el8.remi                          @remi-safe
php74-php-json.x86_64               7.4.12-1.el8.remi                          @remi-safe
php74-runtime.x86_64                1.0-3.el8.remi                             @```

Advertisement

Answer

How do you enable the pdo_sqlsrv extension to a php 7.4 installation using Remi? php-sqlsrv.x86_64 5.8.1-1.el8.remi.7.4 @remi-modular php74-php-fpm.x86_64 7.4.12-1.el8.remi @remi-safe

You are confused betweeen php-* (single/default version) and php74-* (designed for multiple versions installation). Read the repository FAQ

For a proper installation, simply follow the Wizard instruction.

So, if you use php-fpm, you need php-sqlsrv (which is the simpler way, so recommended).

If you use php74-php-fpm, you need php74-php-sqlsrv.

dnf remove php74*
dnf install php-fpm php-cli

You don’t have to build anything from source, and don’t have to modify any INI file.

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement