92

When i try to install php5 in Ubuntu 16.04 by using following code:

sudo apt-get install php5 php5-mcrypt

I get following error:

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

I have tried reinstalling but it does not help.

All this error was encountered after I updated my 15.10 Ubuntu to 16.04

shad0w_wa1k3r
  • 12,955
  • 8
  • 67
  • 90
Srijan Karki
  • 1,576
  • 2
  • 14
  • 21
  • 2
    You can get the answer of this question on below link http://askubuntu.com/questions/756181/installing-php-5-6-on-xenial-16-04/756186#756186 – Prakash Bhandari Apr 24 '16 at 05:24

7 Answers7

138

Ubuntu 16.04 comes with PHP7 as the standard, so there are no PHP5 packages

However if you like you can add a PPA to get those packages anyways:

Remove all the stock php packages

List installed php packages with dpkg -l | grep php| awk '{print $2}' |tr "\n" " " then remove unneeded packages with sudo aptitude purge your_packages_here or if you want to directly remove them all use :

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

Add the PPA

sudo add-apt-repository ppa:ondrej/php

Install your PHP Version

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

You can install php5.6 modules too ..

Verify your version

sudo php -v

Based on https://askubuntu.com/a/756186/532957 (thanks @AhmedJerbi)

Community
  • 1
  • 1
Chris Stadler
  • 1,563
  • 1
  • 15
  • 17
  • 1
    i understand that, but is there any way to make this work in php7 itself? – Srijan Karki Apr 22 '16 at 09:38
  • 1
    @SrijanKarki you can just use `sudo apt-get install php7` to install php7, however I don't get what you mean with "a way to make this work in php7". your question was about installing php5, no? otherwise clarify and I'll edit my answer accordingly – Chris Stadler Apr 22 '16 at 09:50
  • 2
    ya i installed php7 already. And i also tried doing as said in this link. [Here](http://askubuntu.com/questions/387062/how-to-solve-the-phpmyadmin-not-found-issue-after-upgrading-php-and-apache). However, `localhost/phpadmin` page cannot be found. Is there some things that may be causing this error? – Srijan Karki Apr 22 '16 at 09:55
  • @SrijanKarki — So install PHP Admin. It has nothing to do with PHP other than being written in the language. – Quentin Apr 22 '16 at 18:34
  • use prefix "php5.6-" instead of "php5-" as on ubuntu 16.04 as well – Kamaldeep Singh Oct 19 '16 at 08:38
  • Works like a charm. You'll need to install `aptitute` . Run this to install aptitute: `sudo apt-get install aptitude` – Sambruce Sam Dec 04 '17 at 13:44
57

You must use prefix "php5.6-" instead of "php5-" as in ubuntu 14.04 and olders:

sudo apt-get install php5.6 php5.6-mcrypt
Dong Nguyen
  • 1,239
  • 9
  • 17
34

If you just want to install PHP no matter what version it is, try PHP7

sudo apt-get install php7.0 php7.0-mcrypt
Joe zhou
  • 465
  • 3
  • 4
4
sudo apt-get install php7.0-mysql

for php7.0 works well for me

Ericky
  • 654
  • 6
  • 15
1

This worked for me.

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

;)

xereon
  • 66
  • 4
0

Currently, I am using Ubuntu 16.04 LTS. Me too was facing same problem while Fetching the Postgress Database values using Php so i resolved it by using the below commands.

Mine PHP version is 7.0, so i tried the below command.

apt-get install php-pgsql

Remember to restart Apache.

/etc/init.d/apache2 restart
MD Shahrouq
  • 609
  • 8
  • 16
0

I recently had this issue as well and solved it using the following command:

sudo apt install php7.2-cli

php is now installed. I'm using Ubuntu 18.04.

Leanne
  • 53
  • 2
  • 9