无法重新安装 apache2 和 php

无法重新安装 apache2 和 php

我是个新手,在尝试重新安装 apache2 和 php 时弄乱了服务器,我在这个论坛和互联网上进行了广泛的搜索,但没有找到解决类似问题的方法。目前我的网络服务器下载文件而不是打开网页,所以我正在尝试清理我的 php 安装,我想我弄乱了我的软件包列表或 php 安装。

apt-get 安装 php5

    # apt-get install php5Reading package lists... Done
Building dependency tree       
Reading state information... Done
You might want to run 'apt-get -f install' to correct these:
The following packages have unmet dependencies:
 php5 : Depends: libapache2-mod-php5 (>= 5.3.10-1ubuntu3.25) but it is not going to be installed or
                 libapache2-mod-php5filter (>= 5.3.10-1ubuntu3.25) but it is not going to be installed or
                 php5-cgi (>= 5.3.10-1ubuntu3.25) but it is not going to be installed or
                 php5-fpm (>= 5.3.10-1ubuntu3.25) but it is not going to be installed
        Depends: php5-common (>= 5.3.10-1ubuntu3.25) but it is not going to be installed
 php5.6-fpm : Depends: php5.6-common (= 5.6.26-1+deb.sury.org~precise+1) but 5.6.26-2+deb.sury.org~precise+1 is to be installed
E: Unmet dependencies. Try 'apt-get -f install' with no packages (or specify a solution).

apt-get 安装 php

# apt-get install phpReading package lists... Done
Building dependency tree       
Reading state information... Done
You might want to run 'apt-get -f install' to correct these:
The following packages have unmet dependencies:
 php : Depends: php7.0 but it is not going to be installed
 php5.6-fpm : Depends: php5.6-common (= 5.6.26-1+deb.sury.org~precise+1) but 5.6.26-2+deb.sury.org~precise+1 is to be installed
E: Unmet dependencies. Try 'apt-get -f install' with no packages (or specify a solution).

apt-get -f 安装

# apt-get -f installReading package lists... Done
Building dependency tree       
Reading state information... Done
Correcting dependencies... Done
The following extra packages will be installed:
  php5.6-fpm
Suggested packages:
  php-pear
The following packages will be upgraded:
  php5.6-fpm
1 upgraded, 0 newly installed, 0 to remove and 3 not upgraded.
1 not fully installed or removed.
Need to get 0 B/1569 kB of archives.
After this operation, 0 B of additional disk space will be used.
Do you want to continue [Y/n]? Y
dpkg: dependency problems prevent configuration of php5.6-fpm:
 php5.6-fpm depends on php5.6-common (= 5.6.26-1+deb.sury.org~precise+1); however:
  Version of php5.6-common on system is 5.6.26-2+deb.sury.org~precise+1.
dpkg: error processing php5.6-fpm (--configure):
 dependency problems - leaving unconfigured
No apport report written because the error message indicates its a followup error from a previous failure.
                       Errors were encountered while processing:
 php5.6-fpm
E: Sub-process /usr/bin/dpkg returned an error code (1)

任何帮助将不胜感激。

解决方案:

sudo dpkg --remove --force-depends php5.6*
sudo apt-get autoclean
sudo apt-get install php php5.6

看起来问题已经解决了,但我不是 100% 确定,因为我的 Web 服务器仍然无法解释 php,但我不再收到那些令人讨厌的安装错误。

答案1

打开终端并输入

  sudo dpkg --configure -a

如果没有帮助,那么这样做

  sudo apt autoremove <packagename>

如果这没有帮助,那么你需要互联网连接。输入终端

  sudo apt-get autoclean

删除 sources.list 文件并创建新的 sources.list...

sudo rm /etc/apt/sources.list 

然后输入

sudo software-properties-gtk 

在此处输入图片描述 这将打开 software-properties-gtk 并自动创建一个 newsources.list。

然后将服务器更改为美国或您选择的任何其他服务器。您必须从新对话框中启用存储库才能创建新的 sources.list。

勾选所有框然后单击“恢复”,再单击“关闭”。

需要恢复默认存储库

 sudo apt-get update && sudo apt-get dist-upgrade -y

(最好在安装之前备份此文件,以便在发生此类情况时进行恢复)

现在安装任何东西!

更新 :

 sudo apt-get autoclean
 sudo dpkg --remove --force-depends   *put here all the things which are listed in ur Depends: *
  sudo apt-get install -f

更新 2: 创建一个虚拟的 initscript 来欺骗 dpkg:(使用 nano/gedit/vim)

 sudo nano /etc/init.d/php5.6-fpm

输入以下内容:

 #!/bin/bash
  exit 0

保存文件,设置执行权限(sudo chmod 755 /etc/init.d/php5.6-fpm)并重试 sudo apt-get remove php5.6-fpm 。对所有包执行此操作。

相关内容