If you plan to use fpm version of Wordpress image from Docker hub bear in mind, that initially you might get PDO related error messages.
# The Error:
PHP Fatal error: Uncaught Error: Undefined constant PDO::MYSQL_ATTR_INIT_COMMAND
Without being an expert in PHP or Wordpress, writing this diary, so if another wp/php novice encounter it - to be able to quickly get it fixed.
Long story short, i was planning to local host Wordpress and proxy it through local Nginx, alongside other servers - already configured there.
Nginx -> Apache -> Wordpress seemed too much for local installation and that's why i decided to use wordpress fpm image:
All went ok and i proceeded with WooCommerce plugin install until the above error message appear in the container logs. Clearly its PDO mysql driver related.
$ php -m
Showed that only PDO
module itself was installed, but no pdo_mysql.
Went to php.ini and in there ;extension=pdo_mysql
was commented out - ";". Uncomment, save, restart:
"PHP Warning: PHP Startup: Unable to load dynamic library 'pdo_mysql'"
Ah, so the module is not there at all...
$ php -i | grep extension_dir
to locate the extension directory: /usr/local/lib/php/extensions/no-debug-non-zts-20200930
.
No pdo_mysql in there. Strange that it is not included by default in the image.
But, there is way to install it with the tools included:
# Temporary fix:
/usr/local/bin/docker-php-ext-install pdo_install
# Permanent fix:
To fix the image permanently i created new Dockerfile, inheriting the original wordpress fpm image:
FROM wordpress:6.3.2-fpm
RUN apt-get update
RUN /usr/local/bin/docker-php-ext-install pdo_mysql
docker-php-ext-*:
/usr/local/bin/docker-php-ext-* are helper scripts included from the official php image. And they give us the possibility to compile & install an extensions from source. Or to uninstall them if we want to go slim.
Keep in mind that your Wordpress docker installation might work without such errors, depending of the plugins installed and their requirements. In my case the error showed after WooCommerce installation.