Php: PHP Startup: Unable to load dynamic library 'pdo_mysql'

Created on 22 Jan 2018  路  2Comments  路  Source: docker-library/php

Hey guys, I get a weird error I can't solve.

I wanted to add the library hashids and it requires the BC Math or GMP extension. Adding it to my Dockerfile output an error about pdo_mysql that I quite don't understand.

I tried a bunch of things where I went from

RUN apt-get install libgmp-dev -y
RUN apt-get install -y libgmp-dev re2c libmhash-dev libmcrypt-dev file
RUN ln -s /usr/include/x86_64-linux-gnu/gmp.h /usr/local/include/
RUN docker-php-ext-configure gmp
RUN docker-php-ext-install gmp
RUN docker-php-ext-configure bcmath
RUN docker-php-ext-install bcmath

to

RUN apt-get update \
    && apt-get install -y libgmp-dev \
    && ln -s /usr/include/x86_64-linux-gnu/gmp.h /usr/include/gmp.h \
    && docker-php-ext-install \
        gmp \
        bcmath

and with about 1896174 variants in between.

I tried installing only bcmath or only GMP but same result.

One thing to note is that I didn't get any error message when I run the docker without the gmp/bcmath lines and then connect to the bash to install bcmath and/or gmp. Although, it still doesn't detect any extension Missing BC Math or GMP extension. in /var/www/html/vendor/hashids/hashids/src/Math.php

The error I get:

PHP Warning:  PHP Startup: Unable to load dynamic library 'pdo_mysql' (tried: /usr/local/lib/php/extensions/no-debug-non-zts-20170718/pdo_mysql (/usr/local/lib/php/extensions/no-debug-non-zts-20170718/pdo_mysql: cannot open shared object file: No such file or directory), /usr/local/lib/php/extensions/no-debug-non-zts-20170718/pdo_mysql.so (/usr/local/lib/php/extensions/no-debug-non-zts-20170718/pdo_mysql.so: cannot open shared object file: No such file or directory)) in Unknown on line 0
/usr/local/bin/docker-php-ext-enable: 4: cd: can't cd to
Warning: PHP Startup: Unable to load dynamic library 'pdo_mysql' (tried: /usr/local/lib/php/extensions/no-debug-non-zts-20170718/pdo_mysql (/usr/local/lib/php/extensions/no-debug-non-zts-20170718/pdo_mysql: cannot open shared object file: No such file or directory), /usr/local/lib/php/extensions/no-debug-non-zts-20170718/pdo_mysql.so (/usr/local/lib/php/extensions/no-debug-non-zts-20170718/pdo_mysql.so: cannot open shared object file: No such file or directory)) in Unknown on line 0
/usr/local/lib/php/extensions/no-debug-non-zts-20170718

A paste bin with all the build info: https://pastebin.com/fHxbJdJW

Most helpful comment

My guess is that the php.ini you COPY in at the beginning of the build has something that loads pdo_mysql. php is used to find the extension installation directory when using docker-php-ext-install. Try moving the COPY lines to the end of the Dockerfile.

All 2 comments

My guess is that the php.ini you COPY in at the beginning of the build has something that loads pdo_mysql. php is used to find the extension installation directory when using docker-php-ext-install. Try moving the COPY lines to the end of the Dockerfile.

So it seems that is was just the order of the RUN + maybe apt-get update before each install.
It's working with the following code:

# Use the official php library https://hub.docker.com/_/php/ coming directly with apache
FROM php:7.2.1-apache

# Custom Conf
COPY config/php.ini /usr/local/etc/php/
COPY config/httpd.conf /etc/apache2/sites-enabled/000-default.conf

# Including apache expires module
RUN ln -s /etc/apache2/mods-available/expires.load /etc/apache2/mods-enabled/
# Enabling module headers
RUN a2enmod headers

# Install git
RUN apt-get update && apt-get install -y git && apt-get install zip unzip

# Install php extensions
RUN docker-php-ext-configure pdo_mysql && docker-php-ext-install pdo_mysql
RUN apt-get update && apt-get install libgmp-dev -y && \
    apt-get update && apt-get install -y libgmp-dev re2c libmhash-dev libmcrypt-dev file && \
    docker-php-ext-configure gmp && docker-php-ext-install gmp

# Install Composer and move it to bin directory
RUN php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');" &&\
    php -r "if (hash_file('SHA384', 'composer-setup.php') === '544e09ee996cdf60ece3804abc52599c22b1f40f4323403c44d44fdfdd586475ca9813a858088ffbc1f233e9b180f061') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;" &&\
    php composer-setup.php &&\
    php -r "unlink('composer-setup.php');" &&\
    mv composer.phar /usr/local/bin/composer

# Copy composer into docker served directory
COPY ./composer.json /var/www/html/

# Runing composer as non root user
RUN composer install

# Enabling module rewrite
RUN a2enmod rewrite
Was this page helpful?
0 / 5 - 0 ratings