Ubuntu 'Failed to restart apache2.service: Unit apache2.service not found.'

Ubuntu 'Failed to restart apache2.service: Unit apache2.service not found.'

我正在使用 Google Cloud Platform 来测试 ModSecurity,我正在使用教程来启动它。但是,我需要每隔一段时间重新启动 Apache。我正在使用 Ubuntu 18.04。我写 sudo systemctl restart apache2,但返回错误并显示 Failed to restart apache2.service: Unit apache2.service not found。我该怎么办?

你有没有先安装apache2?

sudo apt install apache2

对于那些 运行 使用 Debian 遇到同样问题的人

我确实安装了 apache2 并且 运行ning 已被 apache2.service | loaded active running 确认。

我仍然尝试安装它。

我也遇到了同样的错误Failed to restart apache2.service: Unit apache2.service not found

我如何让 apache2 重新启动

使用:Debian (9.13)

sudo service apache2 restart

或输入

sudo apachectl stop
sudo apachectl start

如果您尝试安装它但仍然遇到同样的问题,您可以更新它,尝试: 易于获取更新

输入 sudo apt install apache2

启动apache服务类型

sudo systemctl 启动 apache2