安装概要:
1.安装odbc驱动程序
2.安装语言的环境(如果已经安装了,可以跳过)
3.安装sqlserver驱动
详情:
1.安装odbc
官网(安装 Microsoft ODBC Driver for SQL Server (Linux) - ODBC Driver for SQL Server | Microsoft Docs)这个目录
选择对应的服务器版本
以Red Hat 为例
依次运行以下命令:
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 and Oracle Linux 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
2.安装sqlserver驱动(我已经安装了对应语言的环境:php)
刚才的官网页面点击
选择对应的语言
以php点击进去为例:
选择要安装的服务器
同样选择对应的版本
然后它上面有详细的步骤
我已经安装好了php运行的环境所以直接安装驱动
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
然后就可以连接sqlserver了,php有时候安装会说某函数用不了,就要去php里面开启.