在 Ubuntu 服务器 16.04 上更新 PHP 包失败

Updating PHP packages on Ubuntu Server 16.04 fails

我正在为我们的 Web 服务器使用 Google 云计算引擎。我们 运行 我们的网络应用程序 PHP7.2 使用 Ondřej Surý 的 PPA。

我们有一个启动脚本来安装所有必需的包并进行配置:

apt install -y apache2 php7.2 php7.2-common php7.2-cli php7.2-mysql php7.2-json php7.2-opcache php7.2-readline php7.2-intl php7.2-mbstring php7.2-zip php7.2-curl php7.2-xml php7.2-memcached php7.2-imagick php7.2-bcmath php7.2-json

a2dismod php7.0
a2enmod php7.2
update-alternatives --set php /usr/bin/php7.2
update-alternatives --set phar /usr/bin/phar7.2
update-alternatives --set phar.phar /usr/bin/phar.phar7.2
update-alternatives --set phpize /usr/bin/phpize7.2
update-alternatives --set php-config /usr/bin/php-config7.2

在虚拟机的初始设置中,一切正常,所有软件包安装都没有问题。

但是当我们需要安装新的 php7.2-XXX 软件包或更新已安装的软件包时,我们总是 运行 出现如下配置错误:

所以当我们 运行 apt -y upgrade 我们最终得到这些错误:

Setting up php7.2-common (7.2.20-1+ubuntu16.04.1+deb.sury.org+1) ...
Internal error!
dpkg: error processing package php7.2-common (--configure):
 subprocess installed post-installation script returned error exit status 1
dpkg: dependency problems prevent configuration of php7.2-curl:
 php7.2-curl depends on php7.2-common (= 7.2.20-1+ubuntu16.04.1+deb.sury.org+1); however:
  Package php7.2-common is not configured yet.

dpkg: error processing package php7.2-json (--configure):
 dependency problems - leaving unconfigured
dpkg: dependency problems prevent configuration of php7.2-opcache:
 php7.2-opcache depends on php7.2-common (= 7.2.20-1+ubuntu16.04.1+deb.sury.org+1); however:
  Package php7.2-common is not configured yet.

...

结束于:

Errors were encountered while processing:
 php7.2-common
 php7.2-json
 php7.2-opcache
 php7.2-readline
 php7.2-cli
 libapache2-mod-php7.2
 php7.2
 php7.2-bcmath
 php7.2-curl
 php7.2-gd
 php7.2-intl
 php7.2-mbstring
 php7.2-mysql
 php7.2-soap
 php7.2-xml
 php7.2-zip
E: Sub-process /usr/bin/dpkg returned an error code (1)

我尝试了什么:

rebooting
apt autoremove
apt autoclean
apt clean
re-running our startup script

dpkg --configure php7.2-common 结果:

Setting up php7.2-common (7.2.20-1+ubuntu16.04.1+deb.sury.org+1) ...
Internal error!
dpkg: error processing package php7.2-common (--configure):
 subprocess installed post-installation script returned error exit status 1
Errors were encountered while processing:
 php7.2-common

幸运的是,我们的网络应用似乎运行良好。 几周来一直在四处寻找有关这些错误的更多信息。

我了解到您目前在尝试 install/update PHP 包时遇到问题,尽管您的实例似乎运行良好;我首先建议您强制安装,以防 'package install' 之前被中断,请尝试以下命令:

sudo apt-get install -f

如果您仍然无法安装PHP 7.2 包,请删除麻烦包的post 信息文件;您可以尝试从 /var/lib/dpkg/info.

中删除与相关包关联的文件

由于您对所有 php7.2 都存在问题,请查找与之关联的文件:

ls -l /var/lib/dpkg/info | grep -i php7.2

此后尝试将它们(暂时)移动到另一个文件夹(参见下面的命令示例):

sudo mv /var/lib/dpkg/info/php7.2-.* /tmp

最后使用 sudo apt update,你应该可以像往常一样安装软件了。请让我知道结果。 我会等你的回复!

弗朗西斯科·Z.