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"]
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?
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.
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.
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