hank
hank

Reputation: 137

Centos 8, PHP 7.2 and MS Sql Server

I am planning moving on to the Centos 8 but it seems that I cannot get a working PDO connection with SQL server using just plain Centos 8 packages.

I have installed the unixODBC packages and after that from PECL sqlsrv and sqlsrv_pdo but I can't figure out how to make the actual connection or odbc configuration.

As most of my code to be transferred to the new environments is written using PDO, I wouldn't want to change it to sql server native.

Are there any step-by-step instructions how to build PDO ODBC connection to sql server without using freetds, which isn't available through the centos repositories (or RHEL either).

Upvotes: 2

Views: 6988

Answers (1)

Pierre
Pierre

Reputation: 1256

I faced the same issue and I solved it as follow:

sudo dnf install php-pear
sudo dnf install php-devel
sudo dnf install make
sudo pecl install sqlsrv
sudo dnf install unixODBC-devel
sudo pecl install sqlsrv
sudo pecl install pdo_sqlsrv

then:

sudo nano /etc/php.d/30-pdo_sqlsrv.ini

Add in the file 30-pdo_sqlsrv.ini:

extension=pdo_sqlsrv.so

then:

sudo nano /etc/php.d/20-sqlsrv.ini

Add in the file 20-sqlsrv.ini:

extension=sqlsrv.so

Download and install msodbcsql17-17.4.2.1-1.x86_64.rpm from https://packages.microsoft.com/rhel/8/prod/

sudo yum install msodbcsql17-17.4.2.1-1.x86_64.rpm

Then just need to restart php-fpm

sudo systemctl restart php-fpm.service

Good luck!

Upvotes: 6

Related Questions