升级到 Ubuntu 22.04 LTS 后 Apache2 将无法启动 - 无法加载 /usr/lib/apache2/moduleslibphp8.0.so

Ric*_*hue 19 php apache webserver reverse-proxy ubuntu-22.04

我对如何解决这个问题有点困惑。我对运行 Apache2 的服务器进行了发行版升级。

自从升级之后就没有用了。我运行了配置测试,下面是错误。我在之前版本的 Ubuntu (21.10) 上的配置没有任何问题

$ apache2ctl configtest
apache2: Syntax error on line 146 of /etc/apache2/apache2.conf: Syntax error on line 3 of /etc/apache2/mods-enabled/php8.0.load: Cannot load /usr/lib/apache2/modules/libphp8.0.so into server: /usr/lib/apache2/modules/libphp8.0.so: cannot open shared object file: No such file or directory
Action 'configtest' failed.
The Apache error log may have more information.
Run Code Online (Sandbox Code Playgroud)

有什么想法从哪里开始吗?我对 Apache 还相当缺乏经验。

Cyr*_*lle 27

当你弄清楚这一点时,其他人(比如我自己)会来看看你是如何做到这一点的。

# perhaps you did the following to see what modules were present
> apache2ctl -M

# the result of the above command may have returned an error such as:
apache2:
 Syntax error on line 146 of /etc/apache2/apache2.conf:
  Syntax error on line 2 of /etc/apache2/mods-enabled/php8.0.load:
   Cannot load /usr/lib/apache2/modules/libphp8.0.so into server:
    /usr/lib/apache2/modules/libphp8.0.so:
     cannot open shared object file: No such file or directory
Action '-M' failed.

# so you removed the problematic module that was no longer installed
# by doing the following (as appropriate given the error above)
> sudo a2dismod php8.0

# you needed to restart your server after that
> sudo systemctl restart apache2

# if you tested the server in a browser html should function...
# however you perhaps desired the use of another php module
# and added another one (8.1) that is install by default in Ubuntu 22.04
> sudo a2enmod php8.1

# you restarted apache again and it worked?
> sudo systemctl restart apache2
Run Code Online (Sandbox Code Playgroud)

也许您正在使用mod_userdir并且还需要更新 apache php 模块配置文件:

/etc/apache2/mods-enabled/php8.1.conf

通过注释掉以下几行:

<IfModule mod_userdir.c>
    <Directory /home/*/public_html>
        php_admin_flag engine Off
    </Directory>
</IfModule>
Run Code Online (Sandbox Code Playgroud)

所以他们看起来像这样:

#<IfModule mod_userdir.c>
#    <Directory /home/*/public_html>
#        php_admin_flag engine Off
#    </Directory>
#</IfModule>
Run Code Online (Sandbox Code Playgroud)
# finally you restarted apache2 again:
sudo systemctl restart apache2
# and everything was back to normal?
Run Code Online (Sandbox Code Playgroud)

你做过这样的事吗?

  • 感谢您的详细回答。很长一段时间没有接触 apache,这让我直接重新开始工作。 (2认同)

小智 17

就我而言,我升级了Ubuntu 20.04 to 22.04。因此向导卸载了php7.4模块并安装了php8.1模块。之后我尝试重新启动 apache2 但没有。我意识到在我的 /etc/apache2/mods-enabled 文件夹中我仍然有php7.4.conf并且php7.4.load仍然php7.4.load指向libphp7.4.so.

请记住,启用 mods 的文件夹是从 mods-available 文件夹生成的,因此您永远不应该更改启用 mods 的文件夹。相反,您应该禁用 php7.4 模块:

sudo a2dismod php7.4
Run Code Online (Sandbox Code Playgroud)

并启用 php8.1 模块:

sudo a2enmod php8.1
Run Code Online (Sandbox Code Playgroud)

当然启用 php8.1 模块后你必须重新启动 apache2 服务。

sudo systemctl restart apache2
Run Code Online (Sandbox Code Playgroud)


Ric*_*hue 6

无视所有人。我想到了。

我检查了/usr/lib/apache2/modules/,发现libphp8.0.so已经更新为libphp8.1.so。

修改 mods-enabled 以包含该文件而不是有问题的文件后,apache 启动时没有任何问题。

  • 欢迎来到 stackoverflow!感谢您的提问 - 我也遇到了同样的问题。 (2认同)