包php5没有安装候选(Ubuntu 16.04)

时间:2016-04-22 08:34:39

标签: php ubuntu apt dpkg ubuntu-16.04

当我尝试使用以下代码在Ubuntu 16.04中安装php5时:

sudo apt-get install php5 php5-mcrypt

我收到以下错误:

Reading package lists... Done
Building dependency tree       
Reading state information... Done
Package php5 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 source

E: Package 'php5' has no installation candidate

我尝试过重新安装,但没有用。

我将15.10 Ubuntu更新为16.04后遇到了所有这个错误

7 个答案:

答案 0 :(得分:128)

Ubuntu 16.04标配PHP7,因此没有PHP5软件包

但是,如果您愿意,可以添加PPA来获取这些包:

删除所有库存的PHP软件包

使用dpkg -l | grep php| awk '{print $2}' |tr "\n" " "列出已安装的php软件包,然后使用sudo aptitude purge your_packages_here删除不需要的软件包,或者如果要直接删除它们,请使用:

sudo aptitude purge `dpkg -l | grep php| awk '{print $2}' |tr "\n" " "`

添加PPA

sudo add-apt-repository ppa:ondrej/php

安装PHP版

sudo apt-get update
sudo apt-get install php5.6

你也可以安装php5.6模块..

验证您的版本

sudo php -v

基于https://askubuntu.com/a/756186/532957(感谢@AhmedJerbi)

答案 1 :(得分:51)

你必须使用前缀" php5.6 - "而不是" php5 - "如在ubuntu 14.04和olders:

sudo apt-get install php5.6 php5.6-mcrypt

答案 2 :(得分:33)

如果您只是想安装PHP,无论它是什么版本,请尝试PHP7

sudo apt-get install php7.0 php7.0-mcrypt

答案 3 :(得分:3)

sudo apt-get install php7.0-mysql

for php7.0对我很有用

答案 4 :(得分:0)

目前,我使用的是Ubuntu 16.04 LTS。 在使用Php获取Postgress数据库值时,我也遇到了同样的问题,所以我使用以下命令解决了这个问题。

我的PHP版本是7.0,所以我尝试了下面的命令。

apt-get install php-pgsql

请记住重启Apache

/etc/init.d/apache2 restart

答案 5 :(得分:0)

我最近也遇到过这个问题,并使用以下命令解决了这个问题:

sudo apt install php7.2-cli

现在安装了php。我使用的是Ubuntu 18.04。

答案 6 :(得分:0)

这对我有用。

sudo apt-get update
sudo apt-get install lamp-server^ -y

;)