Apache PHP 模块未在 22.04 中升级

Apache PHP 模块未在 22.04 中升级

从 21.10 升级到 22.04 后,Apache 服务器不再启动:

apache2:/etc/apache2/apache2.conf 第 146 行语法错误:/etc/apache2/mods-enabled/php8.0.load 第 3 行语法错误:无法将 /usr/lib/apache2/modules/libphp8.0.so 加载到服务器:/usr/lib/apache2/modules/libphp8.0.so:无法打开共享对象文件

这里安装的 PHP 包:

$ dpkg -l | grep php8
ii  libapache2-mod-php8.0                      8.1.2-1ubuntu2                          amd64        Transitional package
ii  libapache2-mod-php8.1                      8.1.2-1ubuntu2                          amd64        server-side, HTML-embedded scripting language (Apache 2 module)
ii  php-symfony-polyfill-php80                 1.24.0-1ubuntu2                         all          Symfony polyfill backporting some PHP 8.0+ features to lower PHP versions
ii  php-symfony-polyfill-php81                 1.24.0-1ubuntu2                         all          Symfony polyfill backporting some PHP 8.1+ features to lower PHP versions
rc  php8.0-bz2                                 8.0.8-1ubuntu0.3                        amd64        bzip2 module for PHP
rc  php8.0-cli                                 8.0.8-1ubuntu0.3                        amd64        command-line interpreter for the PHP scripting language
rc  php8.0-common                              8.0.8-1ubuntu0.3                        amd64        documentation, examples and common module for PHP
rc  php8.0-curl                                8.0.8-1ubuntu0.3                        amd64        CURL module for PHP
rc  php8.0-gd                                  8.0.8-1ubuntu0.3                        amd64        GD module for PHP
rc  php8.0-intl                                8.0.8-1ubuntu0.3                        amd64        Internationalisation module for PHP
rc  php8.0-mbstring                            8.0.8-1ubuntu0.3                        amd64        MBSTRING module for PHP
rc  php8.0-mysql                               8.0.8-1ubuntu0.3                        amd64        MySQL module for PHP
rc  php8.0-opcache                             8.0.8-1ubuntu0.3                        amd64        Zend OpCache module for PHP
rc  php8.0-readline                            8.0.8-1ubuntu0.3                        amd64        readline module for PHP
rc  php8.0-xml                                 8.0.8-1ubuntu0.3                        amd64        DOM, SimpleXML, XML, and XSL module for PHP
rc  php8.0-zip                                 8.0.8-1ubuntu0.3                        amd64        Zip module for PHP
ii  php8.1-bz2                                 8.1.2-1ubuntu2                          amd64        bzip2 module for PHP
ii  php8.1-cli                                 8.1.2-1ubuntu2                          amd64        command-line interpreter for the PHP scripting language
ii  php8.1-common                              8.1.2-1ubuntu2                          amd64        documentation, examples and common module for PHP
ii  php8.1-curl                                8.1.2-1ubuntu2                          amd64        CURL module for PHP
ii  php8.1-gd                                  8.1.2-1ubuntu2                          amd64        GD module for PHP
ii  php8.1-mbstring                            8.1.2-1ubuntu2                          amd64        MBSTRING module for PHP
ii  php8.1-mysql                               8.1.2-1ubuntu2                          amd64        MySQL module for PHP
ii  php8.1-opcache                             8.1.2-1ubuntu2                          amd64        Zend OpCache module for PHP
ii  php8.1-readline                            8.1.2-1ubuntu2                          amd64        readline module for PHP
ii  php8.1-xml                                 8.1.2-1ubuntu2                          amd64        DOM, SimpleXML, XML, and XSL module for PHP
ii  php8.1-zip                                 8.1.2-1ubuntu2                          amd64        Zip module for PHP

可用的库是:

$ ls -l /usr/lib/apache2/modules/libphp*
-rw-r--r-- 1 root root 5354272 apr  7 19:46 /usr/lib/apache2/modules/libphp8.1.so

以下是违规模组的内容:

$ cat /etc/apache2/mods-enabled/php8.0.load
# Conflicts: php5
# Depends: mpm_prefork
LoadModule php_module /usr/lib/apache2/modules/libphp8.0.so

将其更改为libphp8.1.so导致 apache2 服务正确重启。

为什么它没有更新此文件?我应该怎么做才能避免这种手动黑客攻击?

答案1

我遇到了同样的问题,并按照上述步骤解决了该问题:

  1. 删除目录中的旧 php 8.0 引用mods-enabled
  2. mods-enabled在目录中的 php 8.1 引用中添加新的符号链接mods-available

所遵循的步骤概述如下:

决议之前:

$ cd /etc/apache2/mods-enabled  
$ ls -l \*php\*  
lrwxrwxrwx 1 root root 29 May 29 20:27 php8.0.conf -> ../mods-available/php8.0.conf  
lrwxrwxrwx 1 root root 29 May 29 20:27 php8.0.load -> ../mods-available/php8.0.load  

执行决议:

$ sudo rm php8.0.conf php8.0.load  
$ sudo ln -s ../mods-available/php8.1.load php8.1.load  
$ sudo ln -s ../mods-available/php8.1.conf php8.1.conf  

决议后:

$ cd /etc/apache2/mods-enabled  
$ ls -l \*php\*  
lrwxrwxrwx 1 root root 29 Jun  3 12:36 php8.1.conf -> ../mods-available/php8.1.conf  
lrwxrwxrwx 1 root root 29 Jun  3 12:36 php8.1.load -> ../mods-available/php8.1.load  

测试:

$ sudo systemctl restart apache2  
$ sudo systemctl status apache2  
* apache2.service - The Apache HTTP Server
     Loaded: loaded (/lib/systemd/system/apache2.service; enabled; vendor preset: enabled)
     Active: active (running) since Fri 2022-06-03 12:37:30 BST; 5s ago

希望这可以帮助。

答案2

纠结了好久,最后得到的解决方案是这样的:https://idroot.us/install-php-7-4-ubuntu-22-04/

只需按照这些步骤,我的 PHP 网站就可以重新启动并运行。

编辑:以下步骤

sudo apt update
sudo apt upgrade
sudo apt install wget apt-transport-https gnupg2 software-properties-common
sudo add-apt-repository ppa:ondrej/php
sudo apt update
sudo apt install apache2 php7.4 php7.4 php7.4-common libapache2-mod-php7.4 php7.4-cli
sudo apt install php7.4 php7.4-fpm php7.4-cli

相关内容