Lately I was working on a yii project that was connecting to ms sql server. I was setting it up on centos 8.
Steps:
- Install and set up mssql server in the DB server
- Install php and dependencies on the php server
Enable remi repo
sudo dnf install dnf-utils http://rpms.remirepo.net/enterprise/remi-release-8.rpm
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 \
php70-php-zip
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,
/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:
/opt/remi/php70/root/
Binaries here
/opt/remi/php70/root/usr/bin/
Install mssql dependencies
Add repo:
curl https://packages.microsoft.com/config/rhel/8/prod.repo > /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
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
systemctl restart php70-php-fpm