The easy way to achieve that:
- Enable EPEL repository
- Install
php-mssql
. That will installunixODBC
andfreetds
, too.
# yum install php-mssql
Then, you can connect from PHP + PDO (using the dblib driver) from CentOS to your MSSQL server
$dsn = "dblib:host=<host>;dbname=<dbname>";
$user = <user>;
$password = <password>;
$db = new PDO($dsn, $user, $password);
Dockerfile example, but should also work with any CentOS6+ and PHP 7.0:
FROM centos:centos7
RUN yum -y install https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm\
# We include PHP 7 from REMI since it's not in EPEL.
http://rpms.remirepo.net/enterprise/remi-release-7.rpm\
# This will help verify packages and so you will see fewer errors(red) in the build output.
&& rpm --import \
/etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7\
/etc/pki/rpm-gpg/RPM-GPG-KEY-remi\
/etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7\
# Spedify which version of PHP 7 to install here
&& yum-config-manager --enable remi,remi-php70\
&& yum -y install php-mssql