This question already has an answer here:

I installed php5.5 and upgrade Ubuntu from 12 to 14. Now the system isn't working. I did

sudo apt-get upgrade && sudo apt-get install libapache2-mod-php5

But got

The following packages have unmet dependencies:
 libapache2-mod-php5 : Depends: php5-common (= 5.5.9+dfsg-1ubuntu4.4) but 5.5.18+dfsg-1+deb.sury.org~precise+1 is to be installed
E: Unable to correct problems, you have held broken packages.

How do I resolve it?

The commands I used to install php5.5 were like:

add-apt-repository ppa:ondrej/php5-oldstable
apt-get install ppa:ondrej/php5-oldstable
apt-get update
apt-get install php5
apt-get install python-software-properties
add-apt-repository ppa:ondrej/php5
apt-get update
apt-get install php5-common php5-mysql php5-xmlrpc php5-cgi php5-curl php5-gd php5-cli php5-fpm php-apc php-pear php5-dev php5-imap php5-mcrypt

marked as duplicate by David Foerster, Eric Carvalho, edwinksl, Zanna, Aaron Oct 3 '16 at 13:47

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • I found this askubuntu.com/questions/524886/… but I don't know how to replace the version. Can anyone let me know how to remove 5.5.18+dfsg-1+deb.sury.org~precise+1 and install php5-common (= 5.5.9+dfsg-1ubuntu4.4)??? I think that might solve the problem. – heya Oct 23 '14 at 3:57
  • Are you using unofficial PPAs? – Kaz Wolfe Oct 23 '14 at 4:13
  • I don't really know... not a system admin type of guy. I know I installed stock Ubuntu 12 before. I did these to install php 5.5: sudo add-apt-repository ppa:ondrej/php5-oldstable – heya Oct 23 '14 at 4:23
  • apt-get install ppa:ondrej/php5-oldstable apt-get update apt-get install php5 apt-get install python-software-properties add-apt-repository ppa:ondrej/php5 – heya Oct 23 '14 at 4:24
up vote 16 down vote accepted

Your problem is that you have an unofficial PPA which is breaking your install procedure. To remediate this, run the below commands:

sudo add-apt-repository --remove ppa:ondrej/php5-oldstable
sudo add-apt-repository --remove ppa:ondrej/php5

This PPA is providing a different (old) version of PHP instead of the proper version that Ubuntu wants.

Run these commands to add the extra repositories:

sudo add-apt-repository universe
sudo add-apt-repository multiverse

Now, run:

sudo apt-get update

Your repository information will be the official Ubuntu ones. Install libapache2-mod-php5 using this command:

sudo apt-get install libapache2-mod-php5

Note: You may need to uninstall the old PHP packages first. Command:

sudo apt-get remove php5 php5-common php5-mysql php5-xmlrpc php5-cgi php5-curl php5-gd php5-cli php5-fpm php-apc php-pear php5-dev php5-imap php5-mcrypt

You should not add PPAs unless you absolutely need them. They can break more than they solve and can cause problems like this. Also, unofficial PPAs are attack vectors for potential viruses. Unless you really need to use a PPA, don't.

  • Absolutely agreed, it even broke apache2! Many thanks – ackuser May 29 '15 at 12:45
  • 1
    sudo add-apt-repository universe It is failing Error: 'universe' invalid – Vivek Vardhan Oct 28 '15 at 8:03
  • @VivekVardhan Please ask a new question so we can better help you and keep this comment thread clean. Thanks! Feel free to cross-link to this answer if you feel that it's relevant enough. – Kaz Wolfe Oct 28 '15 at 8:05
  • For Error: 'universe' invalid see askubuntu.com/a/227788/41229 – Hugo Feb 8 '16 at 10:11
  • E: Package 'libapache2-mod-php5' has no installation candidate – Just In Time Berlake Jan 11 '17 at 16:48

Not the answer you're looking for? Browse other questions tagged or ask your own question.