Remove PHP Warning “Unable to load dynamic library” mhash after upgrading Ubuntu

After upgrading Ubuntu to 10.04 (give or take a version), you might notice the following warning (or variant) thrown by PHP5:

PHP Warning:  PHP Startup: Unable to load dynamic library '/usr/lib/php5/20090626/mhash.so' - /usr/lib/php5/20090626/mhash.so: cannot open shared object file: No such file or directory in Unknown on line 0

This is the result of the latest version of PHP already having mhash included in the php5-common package.   Even though php5-mhash got removed in the upgrade, the mhash.ini file still references it (and the warning gets thrown).

To fix this, you’ll need to comment out the following line in /etc/php5/cli/conf.d/mhash.ini :

extension=mhash.so

This is a hack, but it removes the tiresome warning.

HOW TO find php.ini in Ubuntu

Looking for the primary php.ini in Ubuntu to change some default settings across Apache?  No problemo.  Here are three different options for finding it:

  • Try running this <?php phpinfo(); ?> through your PHP interpreter.  This will show you where your main php.ini file is.
  • Or you can try searching for it in the shell:  find / -name php.ini
  • If all else fails, give it the old college try, and see if my setting works for you:  /etc/php5/apache2/php.ini (I’m on Ubuntu 9.10 – karmic).

This should just about do it for you, old chap.