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

php5-mysql依赖php5无法安装的Vagrant+Puppet环境求助

Fixing PHP 5.2 Dependency Issues on Ubuntu Trusty64 with Vagrant & Puppet

Let's break down what's going wrong here and get your stack up and running smoothly:

Root Causes of the Error

Your dependency mess boils down to a few key conflicts between Ubuntu Trusty (14.04) and the older Karmic (9.10) repository you're using for PHP 5.2:

  1. APT Repository Priority: Trusty's default repositories have higher priority, so apt is trying to pull newer PHP packages that clash with the 5.2 version you need.
  2. Held/Broken Packages: The error mentions "held broken packages"—this happens when previous failed installs left your package system in an inconsistent state.
  3. PHP API Version Mismatch: phpapi-20060613 is specific to PHP 5.2, but Trusty's system expects a newer API version. We need to force apt to use Karmic versions for all PHP-related packages.

Step-by-Step Fixes

1. Add APT Pinning to Prioritize Karmic PHP Packages

We'll create an APT preferences file to tell apt to always use Karmic for PHP 5.x packages. Update your aptupdate module:

# puppet/modules/aptupdate/manifests/init.pp
class aptupdate {
  # Create pin file to prioritize Karmic for PHP packages
  file { '/etc/apt/preferences.d/php52.pref':
    content => "Package: php5*
Pin: release a=karmic
Pin-Priority: 990
",
    before => Exec['apt-get-update'],
  }

  # Fix any held/broken packages before updating
  exec {"fix-broken-packages":
    command => "apt-get -f install -y",
    path => "/usr/bin",
    onlyif => "dpkg --get-selections | grep -q 'hold'",
    before => Exec['apt-get-update'],
  }

  exec {"apt-get-update":
    command => "apt-get update",
    path => "/usr/bin",
  }
}

2. Adjust PHP 5.2 Package Dependencies & Add Missing System Libraries

PHP 5.2's php5-mysql depends on an older MySQL client library that isn't in Trusty's default repos. We'll add that package and tighten up dependencies in your php52 module:

# puppet/modules/php52/manifests/init.pp
class php52{
  $phpversion = "5.2.10.dfsg.1-2ubuntu6"
  # Older MySQL client library required by PHP 5.2's mysql module
  $mysqlclient_version = "5.1.37-1ubuntu5"

  package { "libmysqlclient15off":
    ensure => $mysqlclient_version,
    require => Exec['apt-get-update'],
  }

  package { "php5":
    ensure => $phpversion,
    require => Exec['apt-get-update'],
  }

  package { "php5-common":
    ensure => $phpversion,
    require => Package["php5"],
  }

  package { "php5-mysql":
    ensure => $phpversion,
    require => [Package["php5-common"], Package["php5"], Package["libmysqlclient15off"]],
  }
}

3. Clean Up & Re-Provision

Before re-running Vagrant, start fresh to avoid residual broken packages:

vagrant destroy -f
vagrant up

Why This Works

  • The APT pin file ensures apt never tries to use Trusty's newer PHP packages for any php5* package.
  • The fix-broken-packages exec clears up any held packages that were blocking installation.
  • Adding libmysqlclient15off resolves the hidden dependency that php5-mysql needs to work with PHP 5.2.
  • Tightening up the require statements ensures packages install in the correct order (core PHP first, then dependencies).

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.15 04:34:06