yii2-docker: PDOException: could not find driver (trying to use mysql)

in my Dockerfile I have:

I have googled and come across what I thought might help (but hasn’t): https://stackoverflow.com/questions/44603941/how-to-enable-pdo-mysql-in-the-php-docker-image

https://stackoverflow.com/questions/49521272/php-docker-pdo-mysql-driver-not-found

# Install system packages
RUN apt-get update && \
    apt-get -y install \
            git \
            unzip \
        --no-install-recommends && \
    apt-get clean && \
    docker-php-ext-install mysqli pdo pdo_mysql && \
    rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*

# Install common system packages for PHP extensions recommended for Yii 2.0 Framework
COPY --from=mlocati/php-extension-installer /usr/bin/install-php-extensions /usr/local/bin/
RUN install-php-extensions \
    soap \
    zip \
    bcmath \
    exif \
    gd \
    opcache \
    #pdo \
    #pdo_mysql \
    # mysqli \
    pdo_pgsql \
    imagick
#        mongodb${PECL_MONGODB_INSTALL_SUFFIX} \
#        xdebug${PECL_XDEBUG_INSTALL_SUFFIX}

# https://stackoverflow.com/questions/44603941/how-to-enable-pdo-mysql-in-the-php-docker-image
RUN docker-php-ext-enable mysqli pdo_mysql

When I log into container (it runs OK), and do a php -m command, I see pdo_mysql is not in list of modules …

File permissions: image

My base.ini (as per this git repo):

; Required timezone
date.timezone = UTC

; General settings
memory_limit=128M
max_execution_time=30
sys_temp_dir=/tmp
upload_max_filesize=512M
upload_tmp_dir=/tmp
post_max_size=512M

; Security, Debug & Logs
expose_php=off
cgi.fix_pathinfo=0
log_errors=on
error_reporting=E_ALL
html_errors=on
xdebug.default_enable=off

; Opcache
opcache.memory_consumption=128
opcache.interned_strings_buffer=8
opcache.max_accelerated_files=4000
;opcache.validate_timestamps=off
opcache.fast_shutdown=0
opcache.enable_cli=1

; PHP language options
short_open_tag=0

; Doesn't work:
; https://stackoverflow.com/questions/49521272/php-docker-pdo-mysql-driver-not-found
;extension=pdo.so
;extension=pdo_mysql.so
;extension=pdo_sqlite.so
;extension=mysql.so

Something is stopping these pdo (and pdo_mysql) modules from either being installed/being enabled I’m not sure how to determine which / how to fix it …

Any help much appreciated, fairly new at docker images!

About this issue

  • Original URL
  • State: closed
  • Created a year ago
  • Comments: 16 (6 by maintainers)

Most upvoted comments

Min image:

> docker-compose run --rm php-min ls  /usr/local/etc/php/conf.d/
Creating yii2fpmnginx_php-min_run ... done
Switching uid for 'www-data' to 33
usermod: no changes
base.ini  docker-fpm.ini  docker-php-ext-intl.ini  docker-php-ext-sodium.ini

Dev image:

> docker-compose run --rm php-dev ls  /usr/local/etc/php/conf.d/
Creating yii2fpmnginx_php-dev_run ... done
Switching uid for 'www-data' to 33
usermod: no changes
base.ini                    docker-php-ext-opcache.ini
docker-fpm.ini              docker-php-ext-pcntl.ini
docker-php-ext-bcmath.ini   docker-php-ext-pdo_mysql.ini
docker-php-ext-exif.ini     docker-php-ext-pdo_pgsql.ini
docker-php-ext-gd.ini       docker-php-ext-soap.ini
docker-php-ext-imagick.ini  docker-php-ext-sodium.ini
docker-php-ext-intl.ini     docker-php-ext-zip.ini
docker-php-ext-mongodb.ini  xdebug.ini

I am closing this, since it’s not an issue with these images to my understanding.

ok thanks let me dig a bit and get back to you, appreciate the help