在 Debian 服务器上为 php 7.4 安装 redis 扩展

问题描述

我想在我的 debian 服务器上安装 PHP7.4-redis。我的PHP是7.4版本。

当我运行“sudo apt install PHP7.4-redis”命令时,它显示 404 not found 所以我无法完成我的设置。

但是,我发现该页面有其他版本: php7.4-redis version

我已经运行命令“sudo apt-get update”来更新存储库,但为什么我仍然收到 404 错误

sudo apt install PHP7.4-redis
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following additional packages will be installed:
PHP7.4-igbinary
The following NEW packages will be installed:
PHP7.4-igbinary PHP7.4-redis
0 upgraded,2 newly installed,0 to remove and 70 not upgraded.
Need to get 142 kB/202 kB of archives.
After this operation,848 kB of additional disk space will be used.
Do you want to continue? [Y/n] y
Err:1 https://packages.sury.org/PHP stretch/main amd64 PHP7.4-redis amd64 5.3.2+4.3.0-7+0~20210228.34+debian9~1.gbp893bd4
404  Not Found
E: Failed to fetch https://packages.sury.org/PHP/pool/main/p/PHP-redis/PHP7.4-redis_5.3.2+4.3.0-7+0~20210228.34+debian9~1.gbp893bd4_amd64.deb  404  Not Found
E: Unable to fetch some archives,maybe run apt-get update or try with --fix-missing?

解决方法

尝试运行 apt update,然后它应该可以工作。

当运行 apt update 时,APT 在本地缓存每个存储库中可用的包。如果你安装了一个包,apt 将使用这个缓存。但是,当服务器上的软件包更新并且旧版本被删除时,apt 将尝试检索不再存在的文件。此日志输出表明:

404  Not Found
E: Failed to fetch https://packages.sury.org/php/pool/main/p/php-redis/php7.4-redis_5.3.2+4.3.0-7+0~20210228.34+debian9~1.gbp893bd4_amd64.deb  404  Not Found

如果您查看 repos listing,您的版本 5.3.2+4.3.0-7+0~20210228.34+debian9~1.gbp893bd4 明显缺失。因此,在 apt update 之后,apt 将知道从哪里加载包。

编辑:您的系统上有来自 php sury 的旧签名密钥,因此无法更新存储库,也无法获取要下载的当前版本。这是known issue,我在所有主机上都遇到过。

在链接的 GitHub 线程中,推荐的修复方法是简单地运行这些命令 (posted by stefanux):

$ apt-key del 95BD4743 # If this throws an error about the key not being present,it's fine
$ wget -O /etc/apt/trusted.gpg.d/php.gpg https://packages.sury.org/php/apt.gpg
$ apt-get update

现在您应该可以安装 redis 包了。