![在 Ubuntu Server 22.04 中对 Apache2 进行故障排除](https://linux22.com/image/948489/%E5%9C%A8%20Ubuntu%20Server%2022.04%20%E4%B8%AD%E5%AF%B9%20Apache2%20%E8%BF%9B%E8%A1%8C%E6%95%85%E9%9A%9C%E6%8E%92%E9%99%A4.png)
sudo apt update
当尝试使用和更新我的系统时sudo apt upgrade
,Apache2 抛出错误并阻止我的系统更新:
$ sudo apt update
Hit:1 http://us.archive.ubuntu.com/ubuntu jammy InRelease
Hit:2 http://us.archive.ubuntu.com/ubuntu jammy-updates InRelease
Hit:3 http://us.archive.ubuntu.com/ubuntu jammy-backports InRelease
Hit:4 http://us.archive.ubuntu.com/ubuntu jammy-security InRelease
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
2 packages can be upgraded. Run 'apt list --upgradable' to see them.
$ sudo apt upgrade
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
Calculating upgrade... Done
The following packages have been kept back:
isc-dhcp-client isc-dhcp-common
0 upgraded, 0 newly installed, 0 to remove and 2 not upgraded.
1 not fully installed or removed.
After this operation, 0 B of additional disk space will be used.
Do you want to continue? [Y/n] y
Setting up apache2 (2.4.52-1ubuntu4.1) ...
info: Executing deferred 'a2enconf javascript-common' for package javascript-common
ERROR: Conf javascript-common does not exist!
dpkg: error processing package apache2 (--configure):
installed apache2 package post-installation script subprocess returned error exit status 1
Errors were encountered while processing:
apache2
E: Sub-process /usr/bin/dpkg returned an error code (1)
正如 Jos 指出的那样,它javascript-common
说不存在,但是当我尝试按照他的建议安装它时,它却说不是这样:
$ sudo apt install javascript-common
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
javascript-common is already the newest version (11+nmu1).
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
1 not fully installed or removed.
After this operation, 0 B of additional disk space will be used.
Do you want to continue? [Y/n]
以下是我能想到的所有输出,但我确信还有更多信息可以找到。不幸的是,我对终端界面还很陌生,我不确定在哪里可以找到故障排除信息。
$ apache2 -v
Server version: Apache/2.4.52 (Ubuntu)
Server built: 2022-06-14T12:30:21
$ apache2 -t
[Tue Aug 23 07:45:27.890824 2022] [core:warn] [pid 921747] AH00111: Config variable ${APACHE_RUN_DIR} is not defined
apache2: Syntax error on line 80 of /etc/apache2/apache2.conf: DefaultRuntimeDir must be a valid directory, absolute or relative to ServerRoot
当我尝试运行调试时,我也收到上述相同的消息:
$ apache2 -X
[Tue Aug 23 07:50:00.684706 2022] [core:warn] [pid 922041] AH00111: Config variable ${APACHE_RUN_DIR} is not defined
apache2: Syntax error on line 80 of /etc/apache2/apache2.conf: DefaultRuntimeDir must be a valid directory, absolute or relative to ServerRoot
当我导航到 时/etc/apache2/apache2.conf
,第 80 行显示以下内容:DefaultRuntimeDir ${APACHE_RUN_DIR}
任何帮助解决此问题的帮助都将不胜感激!如果有帮助的话,该系统上 apache2 的目的是托管 Bitwarden 密码管理器的 Web 服务器。
答案1
问题出现的时候其实是升级到 8.1 的时候 php7.4 残留文件导致的错误,需要删除的残留文件是 php7.4.load 和 php7.4.conf。
为了删除它们,我运行了:
sudo find /etc/apache2 -name "php7.4*" -delete
从 /etc/apache2/mods-available 和 /etc/apache2/mods-enabled 中删除了 php7.4.load 和 php7.4.conf。
我还删除了 /etc/php/7.4,因为它不再安装。
----编辑---- 为了修复 javascript-common 问题,我刚刚清除并重新安装了该包sudo apt purge javascript-common; sudo apt install javascript-common
答案2
我收到此错误是因为更新出于某种原因安装了 Apache,尽管我已经安装了 Nginx。解决方法是简单地删除所有 Apache 包:
sudo apt remove apache2
sudo apt autoremove
然后,如果您确定没有使用 Apache 配置任何重要内容,则可以删除 Apache 配置目录/etc/apache2
。请务必/etc/apache2/sites-available
先检查目录。