Microsoft Drivers PHP cho SQL Server trên CentOS 7
Bước 1: Cài đặt PHP
1 2 3 4 5 6 7 |
yum install https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm yum install https://rpms.remirepo.net/enterprise/remi-release-7.rpm subscription-manager repos --enable=rhel-7-server-optional-rpms yum install yum-utils yum-config-manager --enable remi-php74 yum update yum install php php-pdo php-xml php-pear php-devel re2c gcc-c++ gcc |
1 |
yum --enablerepo=remi-php73 install -y php php-common php-fpm php-mcript php-mbstring php-xml php-curl php-gd php-opcache php-zlib php-zip php-pdo php-json php-imap php-pecl-memcache php-bcmath php-pgsql php-process |
Bước 2: Cài đặt ODBC driver
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
sudo su #Download appropriate package for the OS version #Choose only ONE of the following, corresponding to your OS version #RedHat Enterprise Server 6 curl https://packages.microsoft.com/config/rhel/6/prod.repo > /etc/yum.repos.d/mssql-release.repo #RedHat Enterprise Server 7 curl https://packages.microsoft.com/config/rhel/7/prod.repo > /etc/yum.repos.d/mssql-release.repo #RedHat Enterprise Server 8 and Oracle Linux 8 curl https://packages.microsoft.com/config/rhel/8/prod.repo > /etc/yum.repos.d/mssql-release.repo exit sudo yum remove unixODBC-utf16 unixODBC-utf16-devel #to avoid conflicts sudo ACCEPT_EULA=Y yum install msodbcsql17 # optional: for bcp and sqlcmd sudo ACCEPT_EULA=Y yum install mssql-tools echo 'export PATH="$PATH:/opt/mssql-tools/bin"' >> ~/.bash_profile echo 'export PATH="$PATH:/opt/mssql-tools/bin"' >> ~/.bashrc source ~/.bashrc # optional: for unixODBC development headers sudo yum install unixODBC-devel |
Bước 3: Cài PHP drivers cho Microsoft SQL Server
Cách 1:
1 2 3 4 5 6 |
sudo pecl install sqlsrv sudo pecl install pdo_sqlsrv sudo su echo extension=pdo_sqlsrv.so >> `php --ini | grep "Scan for additional .ini files" | sed -e "s|.*:\s*||"`/30-pdo_sqlsrv.ini echo extension=sqlsrv.so >> `php --ini | grep "Scan for additional .ini files" | sed -e "s|.*:\s*||"`/20-sqlsrv.ini exit |
sudo yum install php-sqlsrv