Can't install pdo_mysql with docker-php-ext-install

Hi!
I need help, I can’t install pdo_mysql with docker-php-ext-install. I prepared a docker project on a local PC (Mac OSX). On the local PC, the PHP configuration is fine. When I deploy the project to the Debian server after building it, I have a completely different PHP version. I mean modules. Missing opcache, pdo_mysql, ampq.

I tried to configure it differently and deleted the cache on the server, but it didn’t help.
docker system prune -a

My PHP dockerfile:

FROM php:7.4-fpm
WORKDIR /var/www/symfony
ENV TZ=Europe/Bratislava
#RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone

RUN apt-get update \
    && docker-php-ext-install mysqli pdo pdo_mysql \
    && docker-php-ext-enable pdo_mysql

RUN apt update && apt-get udpate \
    && apt install -y zlib1g-dev g++ git libicu-dev zip libzip-dev zip libxslt1-dev\
    && docker-php-ext-install intl \
    && pecl install apcu \
    && docker-php-ext-enable apcu \
    && docker-php-ext-configure zip \
    && docker-php-ext-install zip \
    && docker-php-ext-install xsl

RUN apt-get update \
    && docker-php-ext-install opcache

RUN apt-get update \
    && apt-get install -y \
        librabbitmq-dev \
        libssh-dev \
    && pecl install amqp \
    && docker-php-ext-enable amqp

RUN apt-get update && \
    apt-get install -y libxml2-dev \
    && docker-php-ext-install soap

RUN apt-get update && apt-get install -y \
        libfreetype6-dev \
        libjpeg62-turbo-dev \
        libpng-dev \
    && docker-php-ext-configure gd --with-freetype --with-jpeg \
    && docker-php-ext-install -j$(nproc) gd

RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer

# Node.js
RUN curl -sL https://deb.nodesource.com/setup_14.x -o node_setup.sh && \
    bash node_setup.sh && \
    apt-get install -y nodejs && \
    npm install npm -g

# Yarn
RUN curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add - && \
    echo "deb https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list && \
    apt-get update && \
    apt-get install -y yarn

RUN apt-get update && apt-get install -y cron
ADD ./crontab /etc/cron.d/crontab
#
# Give execution rights on the cron job
RUN chmod 0644 /etc/cron.d/crontab
RUN crontab /etc/cron.d/crontab

# Create the log file to be able to run tail
RUN touch /var/log/cron.log

RUN apt-get update && apt-get install -y supervisor
ADD ./supervisord.conf /etc/supervisor/

# Copy docker entrypoint file
COPY ./entrypoint.sh /entrypoint.sh

# Docker init
RUN ["chmod", "+x", "/entrypoint.sh"]

ENTRYPOINT ["/entrypoint.sh"]
CMD ["-f","/dev/null"]

The issue may be with your entrypoint, because I don’t see any problem with the installation of the extensions.

Have you tried the image without supervisor running only php?

Make sure you don’t install anything that installs PHP from an APT repository as a dependency.

By the way, you don’t need to use apt-get update in every layer when you don’t use apt commands after that.

Hi Akos!
I quote: Make sure you don’t install anything that installs PHP from an APT repository as a dependency.
What do you mean?

I tried the PHP installation with only pdo_mysql and that didn’t help either:

FROM php:7.4-fpm
WORKDIR /var/www/symfony
ENV TZ=Europe/Bratislava

RUN apt-get update \
     && docker-php-ext-install mysqli pdo pdo_mysql \
     && docker-php-ext-enable pdo_mysql

How do you know it didn’t help? How did you check it? I used your Dockerfile, apt-get update is still not necessary and it just makes your build slower, but it worked.

docker build . -t localhost/test
docker run --rm -it localhost/test -i | grep mysql
Configure Command =>  './configure'  '--build=aarch64-linux-gnu' '--with-config-file-path=/usr/local/etc/php' '--with-config-file-scan-dir=/usr/local/etc/php/conf.d' '--enable-option-checking=fatal' '--with-mhash' '--with-pic' '--enable-ftp' '--enable-mbstring' '--enable-mysqlnd' '--with-password-argon2' '--with-sodium=shared' '--with-pdo-sqlite=/usr' '--with-sqlite3=/usr' '--with-curl' '--with-iconv' '--with-openssl' '--with-readline' '--with-zlib' '--disable-phpdbg' '--with-pear' '--with-libdir=lib/aarch64-linux-gnu' '--disable-cgi' '--enable-fpm' '--with-fpm-user=www-data' '--with-fpm-group=www-data' 'build_alias=aarch64-linux-gnu'
Additional .ini files parsed => /usr/local/etc/php/conf.d/docker-php-ext-mysqli.ini,
/usr/local/etc/php/conf.d/docker-php-ext-pdo_mysql.ini,
mysqli
Client API library version => mysqlnd 7.4.33
mysqli.allow_local_infile => Off => Off
mysqli.allow_persistent => On => On
mysqli.default_host => no value => no value
mysqli.default_port => 3306 => 3306
mysqli.default_pw => no value => no value
mysqli.default_socket => no value => no value
mysqli.default_user => no value => no value
mysqli.max_links => Unlimited => Unlimited
mysqli.max_persistent => Unlimited => Unlimited
mysqli.reconnect => Off => Off
mysqli.rollback_on_cached_plink => Off => Off
mysqlnd
mysqlnd => enabled
Version => mysqlnd 7.4.33
Loaded plugins => mysqlnd,debug_trace,auth_plugin_mysql_native_password,auth_plugin_mysql_clear_password,auth_plugin_caching_sha2_password,auth_plugin_sha256_password
API Extensions => mysqli,pdo_mysql
PDO drivers => sqlite, mysql
pdo_mysql
Client API version => mysqlnd 7.4.33
pdo_mysql.default_socket => no value => no value
Configure Command =>  './configure'  '--build=x86_64-linux-gnu' '--with-config-file-path=/usr/local/etc/php' '--with-config-file-scan-dir=/usr/local/etc/php/conf.d' '--enable-option-checking=fatal' '--with-mhash' '--with-pic' '--enable-ftp' '--enable-mbstring' '--enable-mysqnd' '--with-password-argon2' '--with-sodium=shared' '--with-pdo-sqlite=/usr' '--with-sqlite3=/usr' '--with-curl' '--with-iconv' '--with-openssl' '--with-readline' '--with-zlib' '--disable-phpdbg' '--with-pear' '--with-libdir=lib/x86_64-linux-gnu' '--disable-cgi' '--enable-fpm' '--with-fpm-user=www-data' '--with-fpm-group=www-data' 'build_alias=x86_64-linux-gnu'
/usr/local/etc/php/conf.d/docker-php-ext-mysqli.ini,
/usr/local/etc/php/conf.d/docker-php-ext-pdo_mysql.ini,
mysqli
Client API library version => mysqlnd 7.4.33
mysqli.allow_local_infile => Off => Off
mysqli.allow_persistent => On => On
mysqli.default_host => no value => no value
mysqli.default_port => 3306 => 3306
mysqli.default_pw => no value => no value
mysqli.default_socket => no value => no value
mysqli.default_user => no value => no value
mysqli.max_links => Unlimited => Unlimited
mysqli.max_persistent => Unlimited => Unlimited
mysqli.reconnect => Off => Off
mysqli.rollback_on_cached_plink => Off => Off
mysqlnd
mysqlnd => enabled
Version => mysqlnd 7.4.33
Loaded plugins => mysqlnd,debug_trace,auth_plugin_mysql_native_password,auth_plugin_mysql_clear_password,auth_plugin_caching_sha2_password,auth_plugin_sha256_password
API Extensions => mysqli,pdo_mysql
PDO drivers => sqlite, mysql
pdo_mysql
Client API version => mysqlnd 7.4.33
pdo_mysql.default_socket => no value => no value

but phpinfo() output print that the pdo_mysql extension is not installed
and when I try to connect to mysql i get: An exception occurred in driver: could not find driver

(5/6) Exception
could not find driver

in Exception.php line 18
at Exception::new(object(PDOException))
in PDOConnection.php line 44
root@b3d540b54220:/var/www/symfony# cat /usr/local/etc/php/conf.d/docker-php-ext-mysqli.ini
cat: /usr/local/etc/php/conf.d/docker-php-ext-mysqli.ini: No such file or directory

Plase, show us how you run php when you call phpinfo(). The extension is installed. The fact that you can’t find ini files does not necccessarily mean anything if that is just a path where you could have an ini.

Can you create a compose file to reproduce the issue?

this is output from php docker container. As you can see no pdo_mysql, no opcache, no ampq :frowning:

root@a51db846dd02:/var/www/symfony# php -i | grep mysql
Configure Command =>  './configure'  '--build=x86_64-linux-gnu' '--with-config-file-path=/usr/local/etc/php' '--with-config-file-scan-dir=/usr/local/etc/php/conf.d' '--enable-option-checking=fatal' '--with-mhash' '--with-pic' '--enable-ftp' '--enable-mbstring' '--enable-mysqlnd' '--with-password-argon2' '--with-sodium=shared' '--with-pdo-sqlite=/usr' '--with-sqlite3=/usr' '--with-curl' '--with-iconv' '--with-openssl' '--with-readline' '--with-zlib' '--disable-phpdbg' '--with-pear' '--with-libdir=lib/x86_64-linux-gnu' '--disable-cgi' '--enable-fpm' '--with-fpm-user=www-data' '--with-fpm-group=www-data' 'build_alias=x86_64-linux-gnu'
mysqlnd
mysqlnd => enabled
Version => mysqlnd 7.4.33
Loaded plugins => mysqlnd,debug_trace,auth_plugin_mysql_native_password,auth_plugin_mysql_clear_password,auth_plugin_caching_sha2_password,auth_plugin_sha256_password

My Docker engine
Docker version 19.03.15, build 99e3ed8919

I have already tried to create a completely new separate project and the result is the same. It is interesting that I have another php project on php 5.6 on the same server and everything is right and pdo_mysql was also installed. Really strange. I’ll try php 5.6, 7.3 and 8.0… I’ll let you know.

FROM php:7.3-fpm
WORKDIR /var/www
ENV TZ=Europe/Bratislava

RUN apt update && apt-get update \
    && apt install -y zlib1g-dev g++ git libicu-dev zip libzip-dev zip libxslt1-dev\
    && docker-php-ext-install intl \
    && pecl install apcu \
    && docker-php-ext-enable apcu \
    && docker-php-ext-configure zip \
    && docker-php-ext-install zip \
    && docker-php-ext-install xsl

RUN docker-php-ext-install mysqli pdo pdo_mysql

RUN docker-php-ext-install opcache

RUN apt-get install -y librabbitmq-dev libssh-dev \
    && pecl install amqp \
    && docker-php-ext-enable amqp

RUN apt-get install -y libxml2-dev \
    && docker-php-ext-install soap




root@d0457023a14a:/var/www# php -i | grep mysql
Configure Command =>  './configure'  '--build=x86_64-linux-gnu' '--with-config-file-path=/usr/local/etc/php' '--with-config-file-scan-dir=/usr/local/etc/php/conf.d' '--enable-option-checking=fatal' '--with-mhash' '--with-pic' '--enable-ftp' '--enable-mbstring' '--enable-mysqlnd' '--with-password-argon2' '--with-sodium=shared' '--with-pdo-sqlite=/usr' '--with-sqlite3=/usr' '--with-curl' '--with-iconv' '--with-openssl' '--with-readline' '--with-zlib' '--disable-phpdbg' '--with-libdir=lib/x86_64-linux-gnu' '--disable-cgi' '--enable-fpm' '--with-fpm-user=www-data' '--with-fpm-group=www-data' 'build_alias=x86_64-linux-gnu'
mysqlnd
mysqlnd => enabled
Version => mysqlnd 5.0.12-dev - 20150407 - $Id: 7cc7cc96e675f6d72e5cf0f267f48e167c2abb23 $
Loaded plugins => mysqlnd,debug_trace,auth_plugin_mysql_native_password,auth_plugin_mysql_clear_password,auth_plugin_sha256_password
mysqlnd statistics =>  
root@d0457023a14a:/var/www# php -v
PHP 7.3.33 (cli) (built: Mar 18 2022 03:18:11) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.3.33, Copyright (c) 1998-2018 Zend Technologies
root@d0457023a14a:/var/www# exit
FROM php:5.6-fpm
WORKDIR /var/www
ENV TZ=Europe/Bratislava

RUN docker-php-ext-install mysqli pdo pdo_mysql

RUN docker-php-ext-install opcache

root@b3a896c6c143:/var/www# php -i | grep mysql
Configure Command =>  './configure'  '--build=x86_64-linux-gnu' '--with-config-file-path=/usr/local/etc/php' '--with-config-file-scan-dir=/usr/local/etc/php/conf.d' '--enable-option-checking=fatal' '--with-mhash' '--enable-ftp' '--enable-mbstring' '--enable-mysqlnd' '--with-curl' '--with-libedit' '--with-openssl' '--with-zlib' '--with-libdir=lib/x86_64-linux-gnu' '--enable-fpm' '--with-fpm-user=www-data' '--with-fpm-group=www-data' '--disable-cgi' 'build_alias=x86_64-linux-gnu' 'CFLAGS=-fstack-protector-strong '-fpic' '-fpie' '-O2'' 'LDFLAGS=-Wl,-O1 '-Wl,--hash-style=both' '-pie'' 'CPPFLAGS=-fstack-protector-strong '-fpic' '-fpie' '-O2''
mysqlnd
mysqlnd => enabled
Version => mysqlnd 5.0.11-dev - 20120503 - $Id: 76b08b24596e12d4553bd41fc93cccd5bac2fe7a $
Loaded plugins => mysqlnd,debug_trace,auth_plugin_mysql_native_password,auth_plugin_mysql_clear_password,auth_plugin_sha256_password
mysqlnd statistics =>  
root@b3a896c6c143:/var/www# php -v
PHP 5.6.40 (cli) (built: Jan 23 2019 00:16:13) 
Copyright (c) 1997-2016 The PHP Group
Zend Engine v2.6.0, Copyright (c) 1998-2016 Zend Technologies
root@b3a896c6c143:/var/www# 

Hi Akos!
So I finally discovered the problem by comparing two phpinfo() pages on the project I built a few days ago and today. The same php configuration in the Dockerfile. The whole problem was in docker-compose.yaml. My mistake. :frowning:

version: '3.9'
services:
  admin_php:
    container_name: hostmagic_php
    build:
      context: ./docker/php
    volumes:
      - .:/var/www/symfony
      - ~/.ssh:/root/.ssh:ro
      - ./docker/php/ini:/usr/local/etc/php
  nginx:
    container_name: hostmagic_nginx
    image: nginx:stable-alpine
    ports:
      - '8080:80'
      - '4443:443'
    volumes:
      - .:/var/www/symfony
      - ./docker/nginx/default.conf:/etc/nginx/conf.d/default.conf
      - /etc/letsencrypt:/etc/letsencrypt
    depends_on:
      - admin_php
  rabbitmq:
    image: rabbitmq:3-management-alpine
    container_name: hostmagic_rabbitmq
    ports:
      - 15672:15672
      - 5672:5672

After removing this line - ./docker/php/ini:/usr/local/etc/php, everything works correctly. All that remains for me is to figure out how to increase the php memory limit in a different way than through the .ini file that I mapped in the given directory.

PHP FPM config files support environment variables. You can add a configuration file to the image that reads the memory limit from an environment variable and you can set that in the compose yaml

https://www.php.net/manual/en/install.fpm.configuration.php.

If you need more help with that, please, open a new topic.

1 Like

I follow the error message of “runc run failed: invalid rootfs: not an absolute path, or a symlink” and according to the link Docker 'is not an absolute path or is a symlink' error - Stack Overflow -or-is-a-symlink-error
It worked for me restarting the docker service.

sudo systemctl restart docker