Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Getting error when installing php5-mysql. Looks like a dpkg error. Perhaps a broken package.

Have tried to fix the broken package. Have reinstalled the lamp server and everything seems fine except being able to install the php5-mysql extension, I get:

Errors were encountered while processing: php5-mysql  

The sub-process for dpkg is returning an error code.

Any ideas appreciated.

share|improve this question
Please give us the complete error. – Dennis Kaarsemaker Nov 13 '12 at 0:20
Please give us a more comprehensive log of the error. – owl Nov 13 '12 at 5:25

This technique is based on owl's answer, but:

  • It avoids deleting the .prerm file. This file is needed to ensure the package is uninstalled cleanly, and removing it could potentially leave traces of the package remaining, leave the system configured in a way that expects the package to be installed, or leave services provided by the package running, even once the files are removed.

    That makes this technique safer, though potentially it might not work if there is also a problem running the .prerm script. (This may have been why owl said to delete it.) Fortunately, usually the .prerm script does not fail.

  • This technique potentially removes more configuration files, so depending on the cause of the problem, this might be more effective.

    It also makes sure we are fetching the correct version of the package to install.


sudo dpkg -P php5-mysql
sudo apt-get --purge autoremove
sudo apt-get update
sudo apt-get install php5-mysql

If there are no errors, then everything is cleaned up from the previous installation and php5-mysql is installed. In that case, the package should work properly now.

share|improve this answer

Why don't you try this command:

sudo rm /var/lib/dpkg/info/php5-mysqlnd.prerm


sudo apt-get autoremove php5-mysql 

This allowed me to install php5-mysql again.

So install php5-mysql again:

sudo apt-get install php5-mysql
share|improve this answer
This is really not a good idea. – Marco Ceppi Nov 13 '12 at 0:29
Why not? I think it works for me. – owl Nov 13 '12 at 0:30
Thanks for the reply. I ended up deleting all the package files relative to mysql and was able to reinstall. – Daryl Wood Nov 19 '12 at 2:59
@DarylWood In that case, you should mark this as the accepted answer, by clicking the gray check mark to the left of it. – Eliah Kagan Dec 26 '12 at 10:05

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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