Ubuntu 18.04-以下软件包具有未满足的依赖项:php7.2-fpm:...如何解决此错误?

Ubuntu 18.04-以下软件包具有未满足的依赖项:php7.2-fpm:...如何解决此错误?

我的 Ubuntu 18.04 中有 php 版本 7.1。

PHP 7.1.33-1+ubuntu16.04.1+deb.sury.org+1 (cli) (built: Oct 26 2019 19:28:18) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.1.0, Copyright (c) 1998-2018 Zend Technologies
    with Zend OPcache v7.1.33-1+ubuntu16.04.1+deb.sury.org+1, Copyright (c) 1999-2018, by Zend Technologies

我想在其上安装 php 7.2 并保留两个版本。按照此邮政我得到了以下输出:

apt-cache pkgnames | grep php7.2

在此处输入图片描述

sudo apt-get install php -y

The following packages have unmet dependencies:
 php : Depends: php7.2 but it is not going to be installed
E: Unable to correct problems, you have held broken packages.

我已经发现类似错误以及可能的解决方案。大部分都是关于 中的内容/etc/apt/sources.list

我刚刚添加了以下内容(取消注释):sudo gedit /etc/apt/sources.list

#deb http://archive.ubuntu.com/ubuntu bionic-security multiverse
#deb http://archive.ubuntu.com/ubuntu bionic-security universe
#deb http://archive.ubuntu.com/ubuntu bionic-updates multiverse
#deb http://archive.ubuntu.com/ubuntu bionic-updates universe

#deb http://archive.ubuntu.com/ubuntu bionic main multiverse restricted universe
#deb http://archive.ubuntu.com/ubuntu bionic-security main multiverse restricted universe
#deb http://archive.ubuntu.com/ubuntu bionic-updates main multiverse restricted universe

deb http://archive.ubuntu.com/ubuntu bionic main restricted universe
deb http://archive.ubuntu.com/ubuntu bionic-updates main restricted universe 
deb http://security.ubuntu.com/ubuntu bionic-security main restricted universe multiverse 
deb http://archive.canonical.com/ubuntu bionic partner

我仍然有同样的错误。这是我在里面的内容ect/php在此处输入图片描述

这是我在 apt 列表中看到的

ila@ila:~$ apt list php
Listing... Done
php/bionic,bionic 1:7.2+60ubuntu1 all
ila@ila:~$ rmadison
E: need at least one package name as an argument.
ila@ila:~$ rmadison php
 php | 1:7.0+35ubuntu6   | xenial         | all
 php | 1:7.0+35ubuntu6.1 | xenial-updates | all
 php | 1:7.2+60ubuntu1   | bionic         | all
 php | 2:7.2+69ubuntu1   | disco          | all
 php | 2:7.3+69ubuntu2   | eoan           | all
 php | 2:7.3+69ubuntu2   | focal          | all
ila@ila:~$ apt list php
Listing... Done
php/bionic,bionic 1:7.2+60ubuntu1 all
ila@ila:~$ sudo apt install php
Reading package lists... Done
Building dependency tree       
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 resolve the situation:

The following packages have unmet dependencies:
 php : Depends: php7.2 but it is not going to be installed
E: Unable to correct problems, you have held broken packages.

删除 7.2 和 7.3 目录后错误仍然存​​在。我该如何解决?

答案1

我找到了答案:

按照此邮政, 我已经做了:

  • sudo add-apt-repository ppa:ondrej/php
  • sudo apt update
  • sudo apt install apt-transport-https lsb-release ca-certificates
  • sudo wget -O /etc/apt/trusted.gpg.d/php.gpg https://packages.sury.org/php/apt.gpg
  • sudo sh -c 'echo "deb https://packages.sury.org/php/ $(lsb_release -sc) main" > /etc/apt/sources.list.d/php.list'
  • sudo apt update
  • dpkg -l | grep php | tee packages.txt(检查内容)
  • sudo apt install php7.2 php7.2-common php7.2-cli php7.2-fpm(安装基本)

然后

php -v
PHP 7.2.24-1+ubuntu18.04.1+deb.sury.org+1 (cli) (built: Oct 24 2019 18:29:11) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies

我的项目仍在使用 php7.1 和新的 7.2。

ila@ila:/etc/php$ ll
total 24
drwxr-xr-x   4 root root  4096 Nov 21 12:24 ./
drwxr-xr-x 161 root root 12288 Nov 21 12:14 ../
drwxr-xr-x   5 root root  4096 Jul 26  2018 7.1/
drwxr-xr-x   5 root root  4096 Nov 21 12:24 7.2/
ila@ila:/etc/php$ tree 7.2/
7.2/
├── cli
│   ├── conf.d
│   │   ├── 10-opcache.ini -> /etc/php/7.2/mods-available/opcache.ini
│   │   ├── 20-json.ini -> /etc/php/7.2/mods-available/json.ini
│   │   └── 20-readline.ini -> /etc/php/7.2/mods-available/readline.ini
│   └── php.ini
├── fpm
│   ├── conf.d
│   │   ├── 10-opcache.ini -> /etc/php/7.2/mods-available/opcache.ini
│   │   ├── 20-json.ini -> /etc/php/7.2/mods-available/json.ini
│   │   └── 20-readline.ini -> /etc/php/7.2/mods-available/readline.ini
│   ├── php-fpm.conf
│   ├── php.ini
│   └── pool.d
│       └── www.conf
└── mods-available
    ├── json.ini
    ├── opcache.ini
    └── readline.ini

6 directories, 13 files

或者安装一些可用的模块

sudo apt install -y php7.2-bz2 php7.2-common php7.2-cgi php7.2-cli php7.2-dba php7.2-dev libphp7.2-embed php7.2-bcmath php7.2-fpm php7.2-gmp php7.2-mysql php7.2-tidy php7.2 php7.2-sqlite3 php7.2-json php7.2-opcache php7.2-sybase php7.2-curl php7.2-ldap php7.2-phpdbg php7.2-imap php7.2-xml php7.2-xsl php7.2-intl php7.2-zip php7.2-odbc php7.2-mbstring php7.2-readline php7.2-gd php7.2-interbase php7.2-snmp php7.2-xmlrpc php7.2-soap php7.2-pspell php7.2-pgsql php7.2-enchant php7.2-recode

答案2

如果你得到错误,如php7.2 php7.2-curl libapache2-mod-php没有可安装的候选包或找不到任何包或依赖项,php7.2-common或者libcurl3这样做。记住根据你的需求更改包名称

你必须以成熟的方式解决。安装 aptitude 这些 ubuntu 包管理器将找到所有依赖项,并逐一安装。

apt-get install aptitude

现在你需要检查 aptitude 是否可以下载它,如果下载请按照说明进行操作

sudo aptitude install php7.2-curl

如果你遇到类似这样的错误

E: Unable to locate package php7.2-curl
E: Couldn't find any package by glob 'php7.2-curl'

任何类型的错误,我不是在谈论这些错误

尝试再次添加 php 包

sudo apt-add-repository ppa:ondrej/php

sudo apt-get update

现在尝试这个命令

sudo aptitude install php7.2-curl

Aptitude 会询问您是否要保留所有依赖项的当前版本

The following actions will resolve these dependencies:

     Keep the following packages at their current version:
1)     php7.2-curl [Not Installed]                        



Accept this solution? [Y/n/q/?]

n然后输入Enter

Aptitude 将找到所有依赖项并要求您安装所有软件包类型

y

再次

y

然后

systemctl restart apache2

对于 centos 或 rhel

systemctl restart httpd

默认情况下不会启用 PHP 7.2 FPM。注意:要在 Apache2 中启用 PHP 7.2 FPM,请执行以下操作

a2enmod proxy_fcgi setenvif

a2enconf php7.2-fpm

此方法不仅适用于此错误,您还可以使用 aptitude 找到任何 php apache2 或 ubuntu 系统包解决方案。

Upvote if you find your solution

相关内容