无法使用PHP从Docker IIS连接到SQL Server

无法使用PHP从Docker IIS连接到SQL Server,php,sql-server,docker,iis,Php,Sql Server,Docker,Iis,我花了好几天时间试图从和PHP运行docker容器,但我不明白 目标是连接到现有的外部Microsoft SQL Server 2000 我尝试了所有的PHP版本,从5.6到7.4,以及它们各自的Visual Studio代码库和PHP ODBC扩展,但都不起作用 我有从科塔纳内部到数据库的ping 最后一次尝试是: 在iis上: php.ini文件: prueba.php文件: 但错误在于: '08001','[08001][Microsoft][ODBC SQL Server

我花了好几天时间试图从和PHP运行docker容器,但我不明白

目标是连接到现有的外部Microsoft SQL Server 2000

我尝试了所有的PHP版本,从5.6到7.4,以及它们各自的Visual Studio代码库和PHP ODBC扩展,但都不起作用

我有从科塔纳内部到数据库的ping

最后一次尝试是:

  • 在iis上:
  • php.ini文件:
  • prueba.php文件:
但错误在于:

'08001','[08001][Microsoft][ODBC SQL Server Driver][DBNETLIB]SQL Server does not exist or access denied.
  • Dockerfile:
#转义=`
#
#此Dockerfile仅供演示之用,Microsoft不支持它
#在IIS上运行的PHP 7.1 x64
#
从mcr.microsoft.com/windows/servercore/iis作为php71
SHELL[“powershell”、“-Command”、“$ErrorActionPreference='Stop';”]
跑`
试试{`
#安装PHP71`
#调用WebRequest'https://sourceforge.net/projects/phpinstallermsi/files/zip/php-7.1.7-nts-Win32-VC14-x64.zip/download'-UserAgent'-OutFile C:\php.zip`
#展开Archive-Path c:\php.zip-DestinationPath c:\php`
`
#安装PHP569`
调用WebRequest'https://windows.php.net/downloads/releases/archives/php-5.6.38-nts-Win32-VC11-x86.zip“-UserAgent”Mozilla/5.0(Windows NT 10.0;Win64;x64)AppleWebKit/537.36(KHTML,像Gecko)Chrome/78.0.3904.87 Safari/537.36'-OutFile C:\php.zip`
展开Archive-Path c:\php.zip-DestinationPath c:\php`
`
#安装Visual Studio代码11(2012)`
调用WebRequest'https://download.microsoft.com/download/1/6/B/16B06F60-3B20-4FF2-B699-5E9B7962F9AE/VSU_4/vcredist_x86.exe'-UserAgent'-OutFile C:\vc\u redist-x64.exe`
`
#安装Visual Studio代码14(2015)`
#调用WebRequest'https://download.microsoft.com/download/6/A/A/6AA4EDFF-645B-48C5-81CC-ED5963AEAD48/vc_redist.x64.exe'-UserAgent'-OutFile C:\vc\u redist-x64.exe`
`
} `
捕获{`
$例外`
$_; `
出口1`
}
添加php.ini-development'C:\php\php.ini'
来自microsoft/iis
COPY--from=php71[“/php/”,“/php/”]
复制--from=php71[“/vc_redist-x64.exe”,“/vc_redist-x64.exe”]
#
#启用所需的IIS功能
#安装VC Redist 14
#配置IIS
#配置系统路径
#
运行dism.exe/Online/Enable Feature/FeatureName:IIS-CGI/All&&`
C:\vc\u redist-x64.exe/quiet/install&&`
#del C:\vc\u redist-x64.exe和`
%windir%\system32\inetsrv\appcmd.exe set-config/section:system.webServer/fastCgi/+[fullPath='c:\PHP\PHP-cgi.exe']&&`
%windir%\system32\inetsrv\appcmd.exe set config/section:system.webServer/handlers/+[name='PHP\u via_FastCGI',path='*.PHP',verb='*',modules='FastCgiModule',scriptProcessor='c:\PHP\PHP cgi.exe',resourceType='or']&`
%windir%\system32\inetsrv\appcmd.exe set config-节:system.webServer/fastCgi/[fullPath='c:\PHP\PHP cgi.exe']。instanceMaxRequests:10000&&`
%windir%\system32\inetsrv\appcmd.exe set config-部分:system.webServer/fastCgi/+[fullPath='c:\PHP\PHP cgi.exe'].environmentVariables.[name='PHP\u FCGI\u MAX\u REQUESTS',value='10000']&&`
%windir%\system32\inetsrv\appcmd.exe set config-部分:system.webServer/fastCgi/+[fullPath='c:\PHP\PHP cgi.exe'].environmentVariables.[name='PHPRC',value='c:\PHP']&&`
%windir%\system32\inetsrv\appcmd.exe set config/section:defaultDocument/enabled:true/+files.[value='index.php']&&`
setx路径/M%路径%;C:\PHP&&`
setx PHP/M“C:\PHP”和`
del C:\inetpub\wwwroot\*/Q
#可选:添加起始页
运行powershell.exe-命令“''|输出文件C:\inetpub\wwwroot\info.php-编码UTF8”
#添加任何应用程序内容并执行以下任何配置
添加prueba.php'C:\inetpub\wwwroot\prueba.php'

任何人都可以帮助我。

“我们的目标是连接到现有的外部Microsoft SQL Server 2000。”为什么您仍在使用SQL Server 2000?近十年来,这一点完全没有得到支持。升级时间已经很长了。数据库更新不是选项,而是客户要求。客户要求有高安全漏洞?你是对的,但你不必说服我。我已经多次告诉客户他应该更新数据库你不能ping数据库,你要ping服务器。使用ICMP协议。假设SQL Server是默认端口上的默认实例,是否允许从容器进行出站tcp/1433连接?
extension=php_pdo_odbc.dll
extension=php_odbc.dll
$connection_string = "Driver={SQL Server};Server=$server;Database=$database;";
$conn = odbc_connect($connection_string,$user,$pass);
var_dump($conn);
'08001','[08001][Microsoft][ODBC SQL Server Driver][DBNETLIB]SQL Server does not exist or access denied.
# escape=`

#
# This Dockerfile is provided for demonstration purposes only and it is not supported by Microsoft
# PHP 7.1 x64 running on IIS
#

FROM mcr.microsoft.com/windows/servercore/iis AS php71

SHELL ["powershell", "-Command", "$ErrorActionPreference = 'Stop';"]

RUN `
    try { `
        # Install PHP 71`
        #Invoke-WebRequest 'https://sourceforge.net/projects/phpinstallermsi/files/zip/php-7.1.7-nts-Win32-VC14-x64.zip/download' -UserAgent '' -OutFile C:\php.zip; `
        #Expand-Archive -Path c:\php.zip -DestinationPath C:\PHP; `
        `
        # Install PHP 569`
        Invoke-WebRequest 'https://windows.php.net/downloads/releases/archives/php-5.6.38-nts-Win32-VC11-x86.zip' -UserAgent 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.87 Safari/537.36' -OutFile C:\php.zip; `
        Expand-Archive -Path c:\php.zip -DestinationPath C:\PHP; `
        `
        # Install Visual Studio Code 11 (2012)`
        Invoke-WebRequest 'https://download.microsoft.com/download/1/6/B/16B06F60-3B20-4FF2-B699-5E9B7962F9AE/VSU_4/vcredist_x86.exe' -UserAgent '' -OutFile C:\vc_redist-x64.exe; `
        `
        # Install Visual Studio Code 14 (2015)`
        #Invoke-WebRequest 'https://download.microsoft.com/download/6/A/A/6AA4EDFF-645B-48C5-81CC-ED5963AEAD48/vc_redist.x64.exe' -UserAgent '' -OutFile C:\vc_redist-x64.exe; `
        `
    } `
    catch { `
        $_.Exception; `
        $_; `
        exit 1; `
    }

ADD php.ini-development 'C:\PHP\php.ini'

FROM microsoft/iis

COPY --from=php71 ["/php/", "/php/"]
COPY --from=php71 ["/vc_redist-x64.exe", "/vc_redist-x64.exe"]

#
# Enable required IIS Features
# Install VC Redist 14
# Configure IIS
# Configure system PATH
#
RUN dism.exe /Online /Enable-Feature /FeatureName:IIS-CGI /All && `
    C:\vc_redist-x64.exe /quiet /install && `
    #del C:\vc_redist-x64.exe && `
    %windir%\system32\inetsrv\appcmd.exe set config /section:system.webServer/fastCgi /+[fullPath='c:\PHP\php-cgi.exe'] && `
    %windir%\system32\inetsrv\appcmd.exe set config /section:system.webServer/handlers /+[name='PHP_via_FastCGI',path='*.php',verb='*',modules='FastCgiModule',scriptProcessor='c:\PHP\php-cgi.exe',resourceType='Either'] && `
    %windir%\system32\inetsrv\appcmd.exe set config -section:system.webServer/fastCgi /[fullPath='c:\PHP\php-cgi.exe'].instanceMaxRequests:10000 && `
    %windir%\system32\inetsrv\appcmd.exe set config -section:system.webServer/fastCgi /+[fullPath='c:\PHP\php-cgi.exe'].environmentVariables.[name='PHP_FCGI_MAX_REQUESTS',value='10000'] && `
    %windir%\system32\inetsrv\appcmd.exe set config -section:system.webServer/fastCgi /+[fullPath='c:\PHP\php-cgi.exe'].environmentVariables.[name='PHPRC',value='C:\PHP'] && `
    %windir%\system32\inetsrv\appcmd.exe set config /section:defaultDocument /enabled:true /+files.[value='index.php'] && `
    setx PATH /M %PATH%;C:\PHP && `
    setx PHP /M "C:\PHP" && `
    del C:\inetpub\wwwroot\* /Q

# Optional: Add a starter page
RUN powershell.exe -Command "'<?php phpinfo(); ?>' | Out-File C:\inetpub\wwwroot\info.php -Encoding UTF8"

# ADD any application content and perform any configuration below
ADD prueba.php 'C:\inetpub\wwwroot\prueba.php'