MYSQL_ATTR_INIT_COMMAND errors showing up in Icingaweb2 after OS (and PHP) upgrade

Written by - 1 comments

Published on - Listed in Icinga Monitoring PHP Linux


After the OS (Ubuntu 16.04) was upgraded to Ubuntu 18.04, Icingaweb2's user interface was suddenly full with errors:

The MySQL related PHP error could also be seen in the Apache error logs:

[Tue Jul 27 11:33:08.176860 2021] [:error] [pid 1479098] [client 10.162.210.49:64794] PHP Fatal error:  Uncaught Error: Undefined class constant 'MYSQL_ATTR_INIT_COMMAND' in /usr/share/php/Icinga/Data/Db/DbConnection.php:203\nStack trace:\n#0 /usr/share/php/Icinga/Data/Db/DbConnection.php(78): Icinga\\Data\\Db\\DbConnection->connect()\n#1 /usr/share/php/Icinga/Data/ResourceFactory.php(103): Icinga\\Data\\Db\\DbConnection->__construct(Object(Icinga\\Data\\ConfigObject))\n#2 /usr/share/icingaweb2/modules/monitoring/library/Monitoring/Backend/MonitoringBackend.php(229): Icinga\\Data\\ResourceFactory::createResource(Object(Icinga\\Data\\ConfigObject))\n#3 /usr/share/icingaweb2/modules/monitoring/library/Monitoring/Backend/MonitoringBackend.php(304): Icinga\\Module\\Monitoring\\Backend\\MonitoringBackend->getResource()\n#4 /usr/share/icingaweb2/modules/monitoring/library/Monitoring/DataView/DataView.php(53): Icinga\\Module\\Monitoring\\Backend\\MonitoringBackend->query('ServiceStatus', Array)\n#5 /usr/share/icingaweb2/modules/monitoring/library/Monitoring/Backend/MonitoringBackend.php(259): Icinga\\Module\\Monitoring\\DataView\\DataView->__constr in /usr/share/php/Icinga/Data/Db/DbConnection.php on line 203, referer: http://10.166.15.51/icingaweb2/dashboard

mod_php enabled -> twice!

A closer look to the installed PHP packages shows that both PHP 7.0 and 7.2 packages exist on this upgraded Ubuntu machine. Interesting however is that the php7.0-mysql package was removed:

root@icingaweb:~# dpkg -l|grep php | awk '{print $1" "$2"\t\t"$3}'
ii icinga-php-common            1.0.0-1.bionic
ii icinga-php-library           0.6.0-1.bionic
ii icinga-php-thirdparty                0.10.0-2.bionic
ii libapache2-mod-php7.0                7.0.33-0ubuntu0.16.04.16
ii libapache2-mod-php7.2                7.2.24-0ubuntu0.18.04.8
ii php          1:7.2+60ubuntu1
ii php-common           1:60ubuntu1
ii php-curl             1:7.0+35ubuntu6.1
rc php-htmlpurifier             4.7.0-1build1
ii php-icinga           2.9.0-1.bionic
ii php-imagick          3.4.3~rc2-2ubuntu4.1
ii php-intl             1:7.2+60ubuntu1
ii php-ldap             1:7.2+60ubuntu1
ii php-mysql            1:7.2+60ubuntu1
ii php-soap             1:7.2+60ubuntu1
ii php-xml              1:7.2+60ubuntu1
ii php7.0               7.0.33-0ubuntu0.16.04.16
ii php7.0-cli           7.0.33-0ubuntu0.16.04.16
ii php7.0-common                7.0.33-0ubuntu0.16.04.16
ii php7.0-curl          7.0.33-0ubuntu0.16.04.16
ii php7.0-fpm           7.0.33-0ubuntu0.16.04.16
ii php7.0-gd            7.0.33-0ubuntu0.16.04.16
ii php7.0-gmp           7.0.33-0ubuntu0.16.04.16
ii php7.0-intl          7.0.33-0ubuntu0.16.04.16
ii php7.0-json          7.0.33-0ubuntu0.16.04.16
ii php7.0-ldap          7.0.33-0ubuntu0.16.04.16
rc php7.0-mysql         7.0.33-0ubuntu0.16.04.16
ii php7.0-opcache               7.0.33-0ubuntu0.16.04.16
ii php7.0-readline              7.0.33-0ubuntu0.16.04.16
ii php7.0-xml           7.0.33-0ubuntu0.16.04.16
ii php7.2               7.2.24-0ubuntu0.18.04.8
ii php7.2-cli           7.2.24-0ubuntu0.18.04.8
ii php7.2-common                7.2.24-0ubuntu0.18.04.8
ii php7.2-intl          7.2.24-0ubuntu0.18.04.8
ii php7.2-json          7.2.24-0ubuntu0.18.04.8
ii php7.2-ldap          7.2.24-0ubuntu0.18.04.8
ii php7.2-mysql         7.2.24-0ubuntu0.18.04.8
ii php7.2-opcache               7.2.24-0ubuntu0.18.04.8
ii php7.2-readline              7.2.24-0ubuntu0.18.04.8
ii php7.2-soap          7.2.24-0ubuntu0.18.04.8
ii php7.2-xml           7.2.24-0ubuntu0.18.04.8

Which PHP version is actually in use by Apache?

root@icingaweb:~# ls -la /etc/apache2/mods-enabled/php*
lrwxrwxrwx 1 root root 29 Dec  7  2017 /etc/apache2/mods-enabled/php7.0.conf -> ../mods-available/php7.0.conf
lrwxrwxrwx 1 root root 29 Dec  7  2017 /etc/apache2/mods-enabled/php7.0.load -> ../mods-available/php7.0.load
lrwxrwxrwx 1 root root 29 Jul 26 11:24 /etc/apache2/mods-enabled/php7.2.conf -> ../mods-available/php7.2.conf
lrwxrwxrwx 1 root root 29 Jul 26 11:24 /etc/apache2/mods-enabled/php7.2.load -> ../mods-available/php7.2.load

Both mod_php versions are enabled since the OS upgrade - which of course does not work and throws a warning:

root@icingaweb:~# apache2ctl configtest
[Tue Jul 27 11:35:50.755188 2021] [so:warn] [pid 1508896] AH01574: module php7_module is already loaded, skipping
Syntax OK

Disable PHP 7.0 and all good

By disabling the PHP 7.0 Apache module, the remaining PHP 7.2 module should be picked up and loaded by Apache:

root@icingaweb:~# a2dismod php7.0
Module php7.0 disabled.
To activate the new configuration, you need to run:
  systemctl restart apache2

root@icingaweb:~# systemctl restart apache2

And as expected, the errors are gone:

Concerning PHP upgrade...

When upgrading PHP with a OS/distribution release upgrade, always make sure to enable only one mod_php Apache module - as Apache runs into a conflict otherwise. Now some people might say that the PHP package upgrade (namely libapache2-mod-php7.2) should properly remove the old PHP version from Apache. But I see it as a "safe" upgrade procedure which allows a quick switch between PHP 7.0 or PHP 7.2 in this particular case (Xenial to Bionic). A systems admin should know the managed system well enough to know how and when to do the switch. But what is confusing me is why the php7.0-mysql package was removed.

The reason can actually be found in the apt history logs and this package (as the sole php package) was removed due to apt autoremove:

Start-Date: 2021-07-26  11:59:34
Commandline: apt autoremove
Remove: libisccfg140:amd64 (1:9.10.3.dfsg.P4-8ubuntu1.19), libmpfr4:amd64 (3.1.4-1), sgml-base:amd64 (1.29), libevent-core-2.0-5:amd64 (2.0.21-stable-2ubuntu0.16.04.1), rename:amd64 (0.20-7), libfile-slurp-tiny-perl:amd64 (0.003-1), libtxc-dxtn-s2tc0:amd64 (0~git20131104-1.1), libpython3.5:amd64 (3.5.2-2ubuntu0~16.04.13), libisc160:amd64 (1:9.10.3.dfsg.P4-8ubuntu1.19), zlib1g-dev:amd64 (1:1.2.11.dfsg-0ubuntu2), python3.5-dev:amd64 (3.5.2-2ubuntu0~16.04.13), libvpx3:amd64 (1.5.0-2ubuntu1.1), python3-pycurl:amd64 (7.43.0.1-0.2), xml-core:amd64 (0.18), libstdc++-5-dev:amd64 (5.5.0-12ubuntu1), libllvm6.0:amd64 (1:6.0-1ubuntu2), libapparmor-perl:amd64 (2.12-4ubuntu5.1), g++-5:amd64 (5.5.0-12ubuntu1), libgdbm3:amd64 (1.8.3-13.1), liblwres141:amd64 (1:9.10.3.dfsg.P4-8ubuntu1.19), liblua5.1-0:amd64 (5.1.5-8.1build2), libpython3.5-dev:amd64 (3.5.2-2ubuntu0~16.04.13), libdbus-glib-1-2:amd64 (0.110-2), libdns162:amd64 (1:9.10.3.dfsg.P4-8ubuntu1.19), rsync:amd64 (3.1.2-2.1ubuntu1.1), libunistring0:amd64 (0.9.3-5.2ubuntu1), imagemagick-common:amd64 (8:6.9.7.4+dfsg-16ubuntu6.11), libisccc140:amd64 (1:9.10.3.dfsg.P4-8ubuntu1.19), libbind9-140:amd64 (1:9.10.3.dfsg.P4-8ubuntu1.19), libboost-iostreams1.58.0:amd64 (1.58.0+dfsg-5ubuntu3.1), libxapian22v5:amd64 (1.2.22-2), php7.0-mysql:amd64 (7.0.33-0ubuntu0.16.04.16)
End-Date: 2021-07-26  11:59:36

This of course does not apply when using PHP-FPM as a separate process daemon for PHP.


Add a comment

Show form to leave a comment

Comments (newest first)

Blacky Forest from wrote on Sep 22nd, 2021:

Thanks! In my case php8.0 was installed by the upgrade, the php7.4-mysql was uninstalled. Reinstalling again fixed the issue!