升级版本后 Apache2 无法启动 22:04

升级版本后 Apache2 无法启动 22:04

将 Ubuntu 16.04 升级到 18.04,然后升级到 20.04,最后升级到 22.04 版本后,出现此错误:

我该如何修复它?

root@vmi155065:/etc/apache2/mods-enabled# sudo service apache2 status
× apache2.service - The Apache HTTP Server
     Loaded: loaded (/lib/systemd/system/apache2.service; enabled; vendor preset: enabled)
     Active: failed (Result: exit-code) since Sun 2022-05-01 17:27:12 CEST; 1 day 20h ago
       Docs: https://httpd.apache.org/docs/2.4/
    Process: 621 ExecStart=/usr/sbin/apachectl start (code=exited, status=1/FAILURE)
        CPU: 31ms

May 01 17:27:12 vmi155065.contaboserver.net systemd[1]: Starting The Apache HTTP Server...
May 01 17:27:12 vmi155065.contaboserver.net apachectl[636]: apache2: Syntax error on line 146 of /etc/apache2/apache2.conf: Syntax error on line 3 of /etc/apache2/mods-enabled/php7.4.load: Cannot >
May 01 17:27:12 vmi155065.contaboserver.net apachectl[621]: Action 'start' failed.
May 01 17:27:12 vmi155065.contaboserver.net apachectl[621]: The Apache error log may have more information.
May 01 17:27:12 vmi155065.contaboserver.net systemd[1]: apache2.service: Control process exited, code=exited, status=1/FAILURE
May 01 17:27:12 vmi155065.contaboserver.net systemd[1]: apache2.service: Failed with result 'exit-code'.
May 01 17:27:12 vmi155065.contaboserver.net systemd[1]: Failed to start The Apache HTTP Server.

答案1

当我从 Ubuntu 20 升级到 22 时,我遇到了完全相同的问题。为了使其正常工作,我做了以下更改。

  • sudo a2dismod php7.4(这是您升级之前使用的 php 版本)
  • sudo a2enmod php8.1(这是升级后的 php 版本。请查看/etc/apache2/mods-available文件夹以验证确切的版本。就我而言,我可以看到最新版本的 php8.1,因此按照此命令中的说明进行操作)
  • systemctl restart apache2
  • sudo apachectl configtest

您可能想了解更多a2dismod关于a2enmode命令的信息?以下链接可以详细解答这个问题a2dismod,a2enmode

答案2

我遇到了同样的问题,本线程中分享的步骤帮助解决了该问题。

libphp 模块加载错误

要成功安装 PHP,您必须先安装一些依赖项。

sudo apt install software-properties-common apt-transport-https

这可能是你的问题和我的问题的不同之处。此步骤是从Ondřej Surý 是一位著名的 PHP 和 Debian 开发人员,负责维护其软件包以及 Ubuntu 的软件包。

sudo add-apt-repository ppa:ondrej/php -y

仅运行更新命令...现在看看这是否有帮助:

sudo apt install php8.1 libapache2-mod-php8.1

现在重新加载:

sudo systemctl restart apache2

检查它是否正常工作:

sudo systemctl status apache2
systemctl status apache2
\u25cf apache2.service - The Apache HTTP
Server
     Loaded: loaded (/lib/systemd/system/apache2.service; enabled; vendor prese>
     Active: active (running) since Thu 2022-06-02 13:13:11 EDT; 8s ago
       Docs: https://httpd.apache.org/docs/2.4/
    Process: 14432 ExecStart=/usr/sbin/apachectl start (code=exited, status=0/S>    Main PID: 14436 (apache2)
      Tasks: 6 (limit: 4622)
     Memory: 9.9M
        CPU: 52ms
     CGroup: /system.slice/apache2.service
             \u251c\u250014436 /usr/sbin/apache2 -k start
             \u251c\u250014437 /usr/sbin/apache2 -k start
             \u251c\u250014438 /usr/sbin/apache2 -k start
             \u251c\u250014439 /usr/sbin/apache2 -k start
             \u251c\u250014440 /usr/sbin/apache2 -k start
             \u2514\u250014441 /usr/sbin/apache2 -k start

答案3

只需确保安装了 php8.1 mod 对我来说就行了。

sudo apt install libapache2-mod-php8.1

答案4

sudo apt install -y libapache2-mod-php7.4

我已经安装了所需 PHP 版本的 libapache2-mod-php,并且运行正常

相关内容