You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Bitbucket Pipelines安装PHP Zip扩展时ZLIB检测失败求助

问题

Bitbucket Pipelines近期突然因PHP Zip库问题构建失败,相关yaml文件已多年未修改,且几周前构建仍正常。尝试更换了多种PHP镜像(包括Apache版和FPM版),也尝试通过配置--with参数指定Zip使用的ZLIB目录,但无论如何操作,构建时都会出现以下错误:

checking libzip... no
configure: error: zip support requires ZLIB. Use --with-zlib-dir=<DIR> to specify prefix where ZLIB include and library are located
2023-05-23T14:44:58.536435778Z stdout P checking for the location of zlib... 

当前使用的bitbucket-pipelines.yml配置:

# registry for your build environment.
image: php:7.0

pipelines:
  default:
    - step:
        caches:
          - composer
        script: # Modify the commands below to build your repository.
          - apt-get update && apt-get install -y unzip zlib1g-dev git
          - curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
          - docker-php-ext-install zip
          - php -v
          - composer --version
          - composer install --no-scripts
          - vendor/bin/phpunit --version
          - vendor/bin/phpunit
解决方法
  • 问题根源:php:7.0镜像基于较新的Debian发行版,其中默认的libzip版本过高,与PHP 7.0的zip扩展不兼容;同时构建脚本中缺少libzip-dev依赖,这是编译zip扩展的必需组件。
  • 修改构建脚本,添加兼容的libzip依赖并正确配置zip扩展:
    1. 添加Debian Jessie源(该版本提供的libzip与PHP7.0兼容),并安装所需依赖:
      apt-get update && apt-get install -y --no-install-recommends apt-transport-https ca-certificates
      echo "deb http://archive.debian.org/debian jessie main" >> /etc/apt/sources.list.d/jessie.list
      echo "deb-src http://archive.debian.org/debian jessie main" >> /etc/apt/sources.list.d/jessie.list
      echo "Acquire::Check-Valid-Until \"false\";" >> /etc/apt/apt.conf.d/10-nocheckvalid
      apt-get update && apt-get install -y unzip zlib1g-dev git libzip-dev
      
    2. 编译zip扩展时指定zlib目录并完成安装:
      docker-php-ext-configure zip --with-zlib-dir=/usr
      docker-php-ext-install zip
      
  • 修改后的完整bitbucket-pipelines.yml:
# registry for your build environment.
image: php:7.0

pipelines:
  default:
    - step:
        caches:
          - composer
        script: # Modify the commands below to build your repository.
          - apt-get update && apt-get install -y --no-install-recommends apt-transport-https ca-certificates
          - echo "deb http://archive.debian.org/debian jessie main" >> /etc/apt/sources.list.d/jessie.list
          - echo "deb-src http://archive.debian.org/debian jessie main" >> /etc/apt/sources.list.d/jessie.list
          - echo "Acquire::Check-Valid-Until \"false\";" >> /etc/apt/apt.conf.d/10-nocheckvalid
          - apt-get update && apt-get install -y unzip zlib1g-dev git libzip-dev
          - curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
          - docker-php-ext-configure zip --with-zlib-dir=/usr
          - docker-php-ext-install zip
          - php -v
          - composer --version
          - composer install --no-scripts
          - vendor/bin/phpunit --version
          - vendor/bin/phpunit

内容的提问来源于stack exchange,提问作者Geoff_S

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.21 10:59:57