无法在带有 WHM/cPanel 的 Ubuntu 22.04 服务器上安装 PHP 7.x – 缺少软件包
问题
正在使用Ubuntu 22.04设置服务器,并使用WHM/cPanel管理多个帐户和配置。我的目标是在服务器上安装 PHP 7.4(或更早的版本,如 PHP 7.3),因为我的一些应用程序与 PHP 8.x 不兼容。问题是,每当我尝试安装 PHP 7.x 时,我都会遇到错误,指出软件包缺失、过时或不可用。
服务器配置
操作系统: Ubuntu Server 22.04 LTS
管理软件: WHM/cPanel
PHP 要求: PHP 7.4、PHP 7.3
问题详细信息
当我尝试为我的一个帐户配置 PHP 7.x 时,我第一次通过 WHM 注意到了这个问题。我意识到 PHP 7.x 软件包默认情况下不可供安装。然后我尝试了多种解决方案来手动安装 PHP 7.x,但都失败了。
到目前为止我尝试过的方法
添加了 SURY PPA 存储库
我添加了ppa:ondrej/php存储库,据说其中包含较旧的 PHP 版本(包括 7.4 和 7.3)。使用的命令:
sudo apt update
sudo add-apt-repository ppa:ondrej/php
sudo apt update
sudo apt install -y php7.4 php7.4-cli php7.4-fpm php7.4-mysql
结果:安装失败,出现错误,例如“包 php7.4-common 不可用,但被另一个包引用。”
尝试直接下载.deb软件包
我.deb手动下载了单个 PHP 7.4 软件包及其依赖项,并尝试使用 进行安装dpkg。手动安装所需的依赖项后,我仍然遇到软件包兼容性问题。
尝试通过 Docker 安装 PHP 7.x(但这并不理想)
我能够在 Docker 容器中运行 PHP 7.4,但理想情况下,我想避免使用 Docker 并将 PHP 7.4 直接安装在服务器上,以便于使用 WHM 进行管理。
检查并重新添加依赖项
在遇到缺少诸如此类的包的依赖项后libicu70,我尝试手动安装依赖项,但仍然不允许安装 PHP 7.x。
错误消息
在尝试安装php7.x的过程中,反复出现的错误是:
root@srv:/# sudo apt install -y php7.3 php7.3-cli php7.3-fpm php7.3-common php7.3-mysql php7.3-zip php7.3-gd php7.3-mbstring php7.3-curl php7.3-xml php7.3-bcmath
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
Package php7.3-common is not available, but is referred to by another package.
This may mean that the package is missing, has been obsoleted, or
is only available from another sourcePackage php7.3-cli is not available, but is referred to by another package.
This may mean that the package is missing, has been obsoleted, or
is only available from another sourcePackage php7.3-mbstring is not available, but is referred to by another package.
This may mean that the package is missing, has been obsoleted, or
is only available from another sourcePackage php7.3-xml is not available, but is referred to by another package.
This may mean that the package is missing, has been obsoleted, or
is only available from another sourcePackage php7.3 is not available, but is referred to by another package.
This may mean that the package is missing, has been obsoleted, or
is only available from another sourcePackage php7.3-fpm is not available, but is referred to by another package.
This may mean that the package is missing, has been obsoleted, or
is only available from another sourcePackage php7.3-bcmath is not available, but is referred to by another package.
This may mean that the package is missing, has been obsoleted, or
is only available from another sourcePackage php7.3-curl is not available, but is referred to by another package.
This may mean that the package is missing, has been obsoleted, or
is only available from another sourcePackage php7.3-gd is not available, but is referred to by another package.
This may mean that the package is missing, has been obsoleted, or
is only available from another sourcePackage php7.3-mysql is not available, but is referred to by another package.
This may mean that the package is missing, has been obsoleted, or
is only available from another sourcePackage php7.3-zip is not available, but is referred to by another package.
This may mean that the package is missing, has been obsoleted, or
is only available from another sourceE: Package 'php7.3' has no installation candidate
E: Package 'php7.3-cli' has no installation candidate
E: Package 'php7.3-fpm' has no installation candidate
E: Package 'php7.3-common' has no installation candidate
E: Package 'php7.3-mysql' has no installation candidate
E: Package 'php7.3-zip' has no installation candidate
E: Package 'php7.3-gd' has no installation candidate
E: Package 'php7.3-mbstring' has no installation candidate
E: Package 'php7.3-curl' has no installation candidate
E: Package 'php7.3-xml' has no installation candidate
E: Package 'php7.3-bcmath' has no installation candidate
root@srv:/#
有没有办法强制 Ubuntu 22.04 安装 PHP 7.x?我是否错过了在此版本的 Ubuntu 上直接安装 PHP 7.3 或 7.4 的任何步骤或替代方法?或者,有没有办法设置 WHM 以使用来自自定义源的 PHP 7.x?
PS:我首先尝试安装php7.4,当完全无法安装时,我尝试了php7.3,但结果是一样的,并且本问题中显示的结果来自php7.3的安装
附言:从技术上讲,我可以通过使用较旧的 Ubuntu 版本创建新磁盘来解决这个问题,但这需要我重新配置整个服务器,包括所有客户端的 WHM 和 cPanel,这非常耗时。老实说,我觉得这不应该是个问题,我不想简单地接受它无法解决。
附言:我对服务器配置还很陌生,因此我在这方面的知识有限。我已尝试严格按照描述遵循每个建议,但可能我遗漏或误解了某些内容。任何指导都将不胜感激!
解决方案
最好升级您的系统以便获得全面支持。
但是如果由于特殊原因您必须坚持在 Ubuntu 22.04 上使用 PHP7.x(在 Ubuntu 22.04 上安装 php7.4 / php7.3),那么您需要执行以下步骤:
sudo apt update
sudo apt upgradesudo apt install software-properties-common curl gnupg2 wget -y
之后,添加存储库
sudo add-apt-repository ppa:ondrej/php
sudo apt update
现在您应该能够安装 PHP 7.x(和相关模块),例如:sudo apt-get install php7.4-cli php7.4-mbstring php7.4-xml php7.4-gd php7.4-mysql php7.4-curl
和sudo apt install -y php7.3 php7.3-cli php7.3-fpm php7.3-mysql php7.3-zip php7.3-gd php7.3-mbstring php7.3-curl php7.3-xml php7.3-bcmath
注意:根据我的经验,您不需要在 apt install 语句中放入 php7.x-common,成功安装 php 7.3/7.4 后,通用模块将自动安装。