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:
- 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.
- Held/Broken Packages: The error mentions "held broken packages"—this happens when previous failed installs left your package system in an inconsistent state.
- PHP API Version Mismatch:
phpapi-20060613is 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-packagesexec clears up any held packages that were blocking installation. - Adding
libmysqlclient15offresolves the hidden dependency thatphp5-mysqlneeds to work with PHP 5.2. - Tightening up the
requirestatements ensures packages install in the correct order (core PHP first, then dependencies).
内容的提问来源于stack exchange,提问作者Thomas
相关产品推荐
相关产品推荐

