Working With Php 7x and mssql server on Centos 8

Pinterest LinkedIn Tumblr

Lately I was working on a yii project that was connecting to ms sql server. I was setting it up on centos 8.


  1. Install and set up mssql server in the DB server
  2. Install php and dependencies on the php server

Enable remi repo

sudo dnf install dnf-utils

Ensure everything is up to date

sudo dnf update

Ensure no previous or any other versions of php exist

dnf module reset php -y
dnf erase php php70 -y

Once that is complete install php and dependencies

dnf install php70 -y
dnf install -y \
    php70-php-fpm \ # to serve php content
    php70-php-pdo \ # for db connectivity
    php70-php-pear \ # to manage php deps with pecl
    php70-php-devel \ # for dev and header files required for installation from source
    php70-php-json \
    php70-php-mbstring \
    php70-php-gd \
    php70-php-xml \

Check ini location files

php70 --inic

This is my output

$ php70 --ini
Configuration File (php.ini) Path: /etc/opt/remi/php70
Loaded Configuration File:         /etc/opt/remi/php70/php.ini
Scan for additional .ini files in: /etc/opt/remi/php70/php.d
Additional .ini files parsed:      /etc/opt/remi/php70/php.d/20-bz2.ini,

The main php ini file can be found in this location here /etc/opt/remi/php70/php.ini

PHP home will be set to:


Binaries here


Install mssql dependencies

Add repo:

curl > /etc/yum.repos.d/mssql-release.repo

Then install

sudo ACCEPT_EULA=Y yum install msodbcsql17
sudo dnf install -y unixODBC-devel

Install sql server drivers. New versions won’t work since this is an old version of php.

/opt/remi/php70/root/usr/bin/pecl install sqlsrv-5.3.0
/opt/remi/php70/root/usr/bin/pecl install pdo_sqlsrv-5.3.0

To enable the drivers:

cat > /etc/opt/remi/php70/php.d/20-sqlsrv.ini <<EOF

cat > /etc/opt/remi/php70/php.d/30-pdo_sqlsrv.ini <<EOF

Then restart php-fpm

systemctl restart php70-php-fpm

I am a Devops Engineer, but I would describe myself as a Tech Enthusiast who is a fan of Open Source, Linux, Automations, Cloud and Virtualization. I love learning and exploring new things so I blog in my free time about Devops related stuff, Linux, Automations and Open Source software. I can also code in Python and Golang.

Write A Comment