需要 ext-sqlsrv 的 Azure DevOps PHP 构建

我正在尝试为我在 Azure DevOps 上托管的 PHP 项目构建一个构建管道。长话短说,我需要为我的构建安装 sqlsrv PHP 扩展。如何配置我的 azure-pipelines.yml 脚本以包含它?


这是我当前的脚本:


trigger:

- master


pool:

  vmImage: 'ubuntu-latest'


variables:

  phpVersion: 7.3


steps:

- script: |

    sudo update-alternatives --set php /usr/bin/php$(phpVersion)

    sudo update-alternatives --set phar /usr/bin/phar$(phpVersion)

    sudo update-alternatives --set phpdbg /usr/bin/phpdbg$(phpVersion)

    sudo update-alternatives --set php-cgi /usr/bin/php-cgi$(phpVersion)

    sudo update-alternatives --set phar.phar /usr/bin/phar.phar$(phpVersion)

    php -version

  displayName: 'Use PHP version $(phpVersion)'


- script: composer install --no-interaction --prefer-dist

  displayName: 'composer install'

这是我在构建日志中得到的错误:


Your requirements could not be resolved to an installable set of packages.


Problem 1

- The requested PHP extension ext-sqlsrv * is missing from your system. Install or enable PHP's sqlsrv extension.


##[error]Bash exited with code '2'.


慕斯709654
浏览 171回答 3
3回答

慕沐林林

Merlin Liang 的回答对我来说是一个很大的启发,但我仍然努力让 SQLSRV 被 Composer 接受。首先,我必须修改一些像 David Legatt 提到的路径。第二个问题是我试图修改并重新启动 FPM。关键是删除重启部分并修改 CLI,而不是 FPM。试试这个,对我有用:- script: sudo apt-get update  displayName: 'Update apt package tool'- script: |    curl -s https://packages.microsoft.com/keys/microsoft.asc | sudo apt-key add -    sudo bash -c "curl -s https://packages.microsoft.com/config/ubuntu/16.04/prod.list > /etc/apt/sources.list.d/mssql-release.list"    sudo ACCEPT_EULA=Y apt-get -y install msodbcsql17 mssql-tools    sudo apt-get -y install unixodbc-dev      displayName: 'SqlSrv prerequisites install'- script: |    sudo apt-get -y install gcc g++ make autoconf libc-dev pkg-config    sudo apt-get install php-pear php-dev    sudo pecl config-set php_ini /etc/php/7.3/fpm/php.ini  displayName: 'PECL install'- script: |    sudo pecl install sqlsrv    sudo pecl install pdo_sqlsrv      displayName: 'SqlSrv extension install'- script: |    sudo bash -c "echo extension=/usr/lib/php/20180731/sqlsrv.so > /etc/php/7.3/cli/conf.d/sqlsrv.ini"    sudo bash -c "echo extension=/usr/lib/php/20180731/pdo_sqlsrv.so > /etc/php/7.3/cli/conf.d/pdo_sqlsrv.ini"      displayName: 'SQLSRV modify ini files'

繁花不似锦

如何配置我的 azure-pipelines.yml 脚本以包含它?作为atymic说,你需要安装PHP Extension Community Library(pecl)有PEAR第一。请尝试在Use PHP version $(phpVersion)任务之前运行以下脚本:- script: |    curl -s https://packages.microsoft.com/keys/microsoft.asc | sudo apt-key add -    sudo bash -c "curl -s https://packages.microsoft.com/config/ubuntu/16.04/prod.list > /etc/apt/sources.list.d/mssql-release.list"    sudo apt-get update    sudo ACCEPT_EULA=Y apt-get -y install msodbcsql17 mssql-tools    sudo apt-get -y install unixodbc-dev- script: |    sudo apt-get -y install gcc g++ make autoconf libc-dev pkg-config    sudo apt-get install php-pear php-dev    sudo pecl install sqlsrv    sudo pecl install pdo_sqlsrv- script: |    sudo bash -c "echo extension=sqlsrv.so > /etc/php7.X-sp/conf.d/sqlsrv.ini"    sudo bash -c "echo extension=pdo_sqlsrv.so > /etc/php7.X-sp/conf.d/pdo_sqlsrv.ini"    sudo service php7.X-fpm-sp restart第一个脚本用于安装先决条件sqlsrv。第二个用于安装扩展。然后,一旦安装,运行第三个脚本任务来为这个扩展创建配置文件,并重新启动你的 PHP。

慕姐4208626

对于那些正在寻找正在运行的 yaml 文件来执行带有 sqlsrv 扩展名的 php 单元测试的人。选择 phpVersion 7.4 很重要。因为最新的 sqlsrv 模块是用比 php 7.3 更新的 php api 编译的。stages:- stage: Build  displayName: Build stage  variables:    phpVersion: '7.4'  jobs:  - job: BuildJob    pool:      vmImage: $(vmImageName)    steps:    - script: |        sudo update-alternatives --set php /usr/bin/php$(phpVersion)        sudo update-alternatives --set phar /usr/bin/phar$(phpVersion)        sudo update-alternatives --set phpdbg /usr/bin/phpdbg$(phpVersion)        sudo update-alternatives --set php-cgi /usr/bin/php-cgi$(phpVersion)        sudo update-alternatives --set phar.phar /usr/bin/phar.phar$(phpVersion)        php -version      workingDirectory: $(rootFolder)      displayName: 'Use PHP version $(phpVersion)'    - script: php -i | grep "Loaded Configuration File"      workingDirectory: $(rootFolder)      displayName: 'Get Ini location'    - script: composer install --no-interaction --prefer-dist      workingDirectory: $(rootFolder)      displayName: 'Composer install'    - script: sudo apt-get update      displayName: 'Update apt package tool'    - script: |        curl -s https://packages.microsoft.com/keys/microsoft.asc | sudo apt-key add -        sudo bash -c "curl -s https://packages.microsoft.com/config/ubuntu/18.04/prod.list > /etc/apt/sources.list.d/mssql-release.list"        sudo ACCEPT_EULA=Y apt-get -y install msodbcsql17 mssql-tools        sudo apt-get -y install unixodbc-dev          displayName: 'SqlSrv prerequisites install'    - script: |        sudo apt-get -y install gcc g++ make autoconf libc-dev pkg-config        sudo apt-get install php-pear php-dev        sudo pecl config-set php_ini /etc/php/7.4/fpm/php.ini      displayName: 'PECL install'    - script: |        sudo pecl install sqlsrv        sudo pecl install pdo_sqlsrv          displayName: 'SqlSrv extension install'    - script: |        sudo bash -c "echo extension=/usr/lib/php/20190902/sqlsrv.so > /etc/php/7.4/cli/conf.d/99-sqlsrv.ini"        sudo bash -c "echo extension=/usr/lib/php/20190902/pdo_sqlsrv.so > /etc/php/7.4/cli/conf.d/99-sqlsrv.ini"          displayName: 'SQLSRV modify ini files'    - script: vendor/bin/phpunit      workingDirectory: $(rootFolder)      displayName: 'Run PHP tests with phpunit'
打开App,查看更多内容
随时随地看视频慕课网APP