Working With Php 7x and mssql server on Centos 8

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

Steps:

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

Enable remi repo

1
sudo dnf install dnf-utils http://rpms.remirepo.net/enterprise/remi-release-8.rpm

Ensure everything is up to date

1
sudo dnf update

Ensure no previous or any other versions of php exist

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

Once that is complete install php and dependencies

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
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 \
    php70-php-zip

Check ini location files

1
php70 --ini

This is my output

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
$ 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,
/etc/opt/remi/php70/php.d/20-calendar.ini,
/etc/opt/remi/php70/php.d/20-ctype.ini,
/etc/opt/remi/php70/php.d/20-curl.ini,
/etc/opt/remi/php70/php.d/20-dom.ini,
/etc/opt/remi/php70/php.d/20-exif.ini,
/etc/opt/remi/php70/php.d/20-fileinfo.ini,
/etc/opt/remi/php70/php.d/20-ftp.ini,
/etc/opt/remi/php70/php.d/20-gd.ini,
/etc/opt/remi/php70/php.d/20-gettext.ini,
/etc/opt/remi/php70/php.d/20-iconv.ini,
/etc/opt/remi/php70/php.d/20-json.ini,
/etc/opt/remi/php70/php.d/20-mbstring.ini,
/etc/opt/remi/php70/php.d/20-pdo.ini,
/etc/opt/remi/php70/php.d/20-phar.ini,
/etc/opt/remi/php70/php.d/20-posix.ini,
/etc/opt/remi/php70/php.d/20-shmop.ini,
/etc/opt/remi/php70/php.d/20-simplexml.ini,
/etc/opt/remi/php70/php.d/20-sockets.ini,
/etc/opt/remi/php70/php.d/20-sqlite3.ini,
/etc/opt/remi/php70/php.d/20-sqlsrv.ini,
/etc/opt/remi/php70/php.d/20-sysvmsg.ini,
/etc/opt/remi/php70/php.d/20-sysvsem.ini,
/etc/opt/remi/php70/php.d/20-sysvshm.ini,
/etc/opt/remi/php70/php.d/20-tokenizer.ini,
/etc/opt/remi/php70/php.d/20-xml.ini,
/etc/opt/remi/php70/php.d/20-xmlwriter.ini,
/etc/opt/remi/php70/php.d/20-xsl.ini,
/etc/opt/remi/php70/php.d/30-pdo_sqlite.ini,
/etc/opt/remi/php70/php.d/30-pdo_sqlsrv.ini,
/etc/opt/remi/php70/php.d/30-wddx.ini,
/etc/opt/remi/php70/php.d/30-xmlreader.ini,
/etc/opt/remi/php70/php.d/30-zip.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:

1
/opt/remi/php70/root/

Binaries here

1
/opt/remi/php70/root/usr/bin/

Install mssql dependencies

Add repo:

1
curl https://packages.microsoft.com/config/rhel/8/prod.repo > /etc/yum.repos.d/mssql-release.repo

Then install

1
2
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.

1
2
/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:

1
2
3
4
5
6
7
cat > /etc/opt/remi/php70/php.d/20-sqlsrv.ini <<EOF
extension=sqlsrv.so
EOF

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

Then restart php-fpm

1
sudo systemctl restart php70-php-fpm
comments powered by Disqus
Built with Hugo
Theme Stack designed by Jimmy