如何解决在 WSL2 Ubuntu 上安装 PHP 的错误?

如何解决在 WSL2 Ubuntu 上安装 PHP 的错误?

我使用 WSL2 Ubuntu 22.04 LTS 并尝试安装 PHP 8.2。

sudo add-apt-repository ppa:ondrej/php
sudo apt update
sudo apt upgrade
sudo apt install php8.2

然后错误随之而来。

libapache2-mod-php8.2 depends on php8.2-common (= 8.2.8-1+ubuntu22.04.1+deb.sury.org+1); however:
  Package php8.2-common is not configured yet.
 libapache2-mod-php8.2 depends on php8.2-opcache; however:
  Package php8.2-opcache is not configured yet.

dpkg: error processing package libapache2-mod-php8.2 (--configure):
 dependency problems - leaving unconfigured
dpkg: dependency problems prevent configuration of php8.2-cli:
 php8.2-cli depends on php8.2-common (= 8.2.8-1+ubuntu22.04.1+deb.sury.org+1); however:
  Package php8.2-common is not configured yet.
 php8.2-cli depends on php8.2-opcache; however:
  Package php8.2-opcache is not configured yet.
 php8.2-cli depends on php8.2-readline; however:
  Package php8.2-readline is not configured yet.

dpkg: error processing package php8.2-cli (--configure):
 dependency problems - leaving unconfigured
Processing triggers for man-db (2.10.2-1) ...
Errors were encountered while processing:
 php8.2-common
 php8.2-opcache
 php8.2-readline
 php8.2
 libapache2-mod-php8.2
 php8.2-cli
E: Sub-process /usr/bin/dpkg returned an error code (1)

我尝试了重新安装 PHP 的命令:

sudo apt remove --purge
sudo apt autoremove
sudo apt autoclean
sudo apt update
sudo apt install php8.2

那么错误是一样的。

以下是我的 PHP 软件包列表。(dpkg -l | grep \php

iU  libapache2-mod-php8.2          8.2.8-1+ubuntu22.04.1+deb.sury.org+1         amd64        server-side, HTML-embedded scripting language (Apache 2 module)
ii  php-common                     2:93+ubuntu22.04.1+deb.sury.org+2            all          Common files for PHP packages
iU  php8.2                         8.2.8-1+ubuntu22.04.1+deb.sury.org+1         all          server-side, HTML-embedded scripting language (metapackage)
iU  php8.2-cli                     8.2.8-1+ubuntu22.04.1+deb.sury.org+1         amd64        command-line interpreter for the PHP scripting language
iF  php8.2-common                  8.2.8-1+ubuntu22.04.1+deb.sury.org+1         amd64        documentation, examples and common module for PHP
iU  php8.2-opcache                 8.2.8-1+ubuntu22.04.1+deb.sury.org+1         amd64        Zend OpCache module for PHP
iU  php8.2-readline                8.2.8-1+ubuntu22.04.1+deb.sury.org+1         amd64        readline module for PHP

我尝试了各种命令:

sudo apt remove --purge [packagename]
sudo apt autoremove
sudo apt autoclean
sudo dpkg --purge [packagename]
sudo dpkg --configure -a

相关内容