php - 如何在 Ubuntu 22 的 Apache 中使用 Php7.4?

标签 php apache ubuntu

最近我将我的 Ubuntu 从 20 升级到 22。我在 Ubuntu 20 中使用 Php7.4 和 Apache 服务器。升级到 Ubuntu 22 后,Php 会自动升级到 8.1。之后,我也在我的系统中安装了 Php7.4。我可以使用以下命令切换 PHP 版本:

sudo update-alternatives --config php
如果我使用终端,我可以使用 php -v 查看不同的 PHP 版本.但我无法在 apache 中使用 Php7.4。我正在尝试使用以下命令进行安装:
sudo apt-get install libapache2-mod-php7.4
但它给了我以下错误:
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
Some packages could not be installed. This may mean that you have
requested an impossible situation or if you are using the unstable
distribution that some required packages have not yet been created
or been moved out of Incoming.
The following information may help to resolve the situation:

The following packages have unmet dependencies:
 libapache2-mod-php7.4 : Depends: php8.1-common (= 8.1.2-1ubuntu2) but 8.1.5-1+ubuntu22.04.1+deb.sury.org+1.1 is to be installed
E: Unable to correct problems, you have held broken packages.
同样,如果我尝试使用以下命令在 apache 中激活 Php7.4:
sudo a2enmod php7.4
我收到此错误:
ERROR: Module php7.4 does not exist!
现在如何在我的 Apache 中使用 Php7.4?请注意,Apache 安装在 Ubuntu 20 中。

最佳答案

您需要禁用 PHP 8.1 并启用 php 7.4
尝试这个:

sudo a2dismod php8.1
后:
sudo a2enmod php7.2

关于php - 如何在 Ubuntu 22 的 Apache 中使用 Php7.4?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/72047222/

相关文章:

php - 在php中将三个mysql查询组合成一个json数组

php - Zend Framework 2 - 数据库连接

linux - 在 Apache 配置中有条件地设置环境变量

php - 如何跟踪文件下载

linux - Docker 只监听 8080 端口

javascript - 使用 JavaScript AJAX 调用 PHP 后端打开 PDF

php - MySql 'or' 运算符不工作

java - 安装 Tomcat (Ubuntu) 时出现 gzip & tar 错误

linux - Puppet 主代理配置

c++ - 添加自定义 TensorFlow OP