简体   繁体   中英

The pdo_mysql extension is not detected on Wordpress Docker container

I have installed several Wordpress websites by using Docker, specifically this Docker Wordpress Let's Encrypt repo by Evert Ramos.

While it makes it easy and fast to deploy as many Wordpress installations as you want, there're still some issues and lacks, such as the sendmail() function (then you have to install an SMTP plugin to work around the email sending).

The main issue I have found is that, after having installed this WPvivid plugin for backing up Wordpress, I get the following error message:

The pdo_mysql extension is not detected. Please install the extension first.

I have googled how to install the pdo_mysql extension for a Wordpress container or inside the Nginx container. However, I only have found answers about how to install it but for a PHP container.

The Evert Ramos ' repos do not use any PHP container, so I haven't found out how or where to install that pdo_mysql extension.

Here is my docker-compose.yml file of one of the Wordpress sites:

    services:
        db_projects:
          container_name: ${CONTAINER_DB_NAME}
          image: mariadb:10.4
          restart: unless-stopped
          volumes:
            - ${DB_PATH}:/var/lib/mysql
          environment:
            MYSQL_ROOT_PASSWORD: ${MYSQL_ROOT_PASSWORD}
            MYSQL_DATABASE: ${MYSQL_DATABASE}
            MYSQL_USER: ${MYSQL_USER}
            MYSQL_PASSWORD: ${MYSQL_PASSWORD}

        wp_projects:
          depends_on:
            - db_projects
          container_name: ${CONTAINER_WP_NAME}
          image: wordpress:latest
          restart: unless-stopped
          volumes:
            - ${WP_CORE}:/var/www/html
            - ${WP_CONTENT}:/var/www/html/wp-content
            - ./conf.d/php.ini:/usr/local/etc/php/conf.d/php.ini
          environment:
            WORDPRESS_DB_HOST: ${CONTAINER_DB_NAME}:3306
            WORDPRESS_DB_NAME: ${MYSQL_DATABASE}
            WORDPRESS_DB_USER: ${MYSQL_USER}
            WORDPRESS_DB_PASSWORD: ${MYSQL_PASSWORD}
            WORDPRESS_TABLE_PREFIX: ${WORDPRESS_TABLE_PREFIX}
            VIRTUAL_HOST: ${DOMAINS}
            LETSENCRYPT_HOST: ${DOMAINS}
            LETSENCRYPT_EMAIL: ${LETSENCRYPT_EMAIL}
          logging:
            options:
          max-size: ${LOGGING_OPTIONS_MAX_SIZE:-200k}
    pma_projects:
      image: phpmyadmin/phpmyadmin
      restart: unless-stopped
      container_name: pma_projects
      links:
        - db_projects
      ports:
        - ${PMA_PORT}:80
      environment:
        #MYSQL_USERNAME: root
        #MYSQL_ROOT_PASSWORD: ${MYSQL_ROOT_PASSWORD}
        PMA_HOST: db_projects
        PMA_PORT: 3306
        #PMA_USER: ${MYSQL_USER}
        #PMA_PASSWORD: ${MYSQL_PASSWORD}
        PMA_ARBITRARY: 1
      depends_on:
        - wp_projects
        - db_projects

#   wpcli:
#     image: tatemz/wp-cli
#     volumes:
#       - ${WP_CORE}:/var/www/html
#       - ${WP_CONTENT}:/var/www/html/wp-content
#     depends_on:
#       - db
#     entrypoint: wp

networks:
    default:
       external:
         name: ${NETWORK}

Any ideas on how to install that extension or somebody who can shed some light to solve this?

(my useful links on my way to solve it: https://docs.docker.com/samples/library/wordpress/ & https://github.com/docker-library/wordpress/blob/c9f1ca12b6fa8181dee161dfc5ce1692eeaef1d1/php7.2/apache/Dockerfile | https://github.com/docker-library/wordpress/blob/c9f1ca12b6fa8181dee161dfc5ce1692eeaef1d1/php7.3/fpm/Dockerfile )

Following Anh Tuan's answer, my dockerfile is as follows:

FROM php:7.3-fpm

# install the PHP extensions we need (https://make.wordpress.org/hosting/handbook/handbook/server-environment/#php-extensions)
RUN set -ex; \
    \
    savedAptMark="$(apt-mark showmanual)"; \
    \
    apt-get update; \
    apt-get install -y --no-install-recommends \
        libjpeg-dev \
        libmagickwand-dev \
        libpng-dev \
        libzip-dev \
    ; \
    \
    docker-php-ext-configure gd --with-png-dir=/usr --with-jpeg-dir=/usr; \
    docker-php-ext-install -j "$(nproc)" \
        bcmath \
        exif \
        gd \
        mysqli \
        opcache \
        zip \
                pdo_mysql \
    ; \
    pecl install imagick-3.4.4; \
    docker-php-ext-enable imagick; \
    \
# reset apt-mark's "manual" list so that "purge --auto-remove" will remove all build dependencies
    apt-mark auto '.*' > /dev/null; \
    apt-mark manual $savedAptMark; \
    ldd "$(php -r 'echo ini_get("extension_dir");')"/*.so \
        | awk '/=>/ { print $3 }' \
        | sort -u \
        | xargs -r dpkg-query -S \
        | cut -d: -f1 \
        | sort -u \
        | xargs -rt apt-mark manual; \
    \
    apt-get purge -y --auto-remove -o APT::AutoRemove::RecommendsImportant=false; \
    rm -rf /var/lib/apt/lists/*

# set recommended PHP.ini settings
# see https://secure.php.net/manual/en/opcache.installation.php
RUN { \
        echo 'opcache.memory_consumption=128'; \
        echo 'opcache.interned_strings_buffer=8'; \
        echo 'opcache.max_accelerated_files=4000'; \
        echo 'opcache.revalidate_freq=2'; \
        echo 'opcache.fast_shutdown=1'; \
    } > /usr/local/etc/php/conf.d/opcache-recommended.ini
# https://wordpress.org/support/article/editing-wp-config-php/#configure-error-logging
RUN { \
# https://www.php.net/manual/en/errorfunc.constants.php
# https://github.com/docker-library/wordpress/issues/420#issuecomment-517839670
        echo 'error_reporting = E_ERROR | E_WARNING | E_PARSE | E_CORE_ERROR | E_CORE_WARNING | E_COMPILE_ERROR | E_COMPILE_WARNING | E_RECOVERABLE_ERROR'; \
        echo 'display_errors = Off'; \
        echo 'display_startup_errors = Off'; \
        echo 'log_errors = On'; \
        echo 'error_log = /dev/stderr'; \
        echo 'log_errors_max_len = 1024'; \
        echo 'ignore_repeated_errors = On'; \
        echo 'ignore_repeated_source = Off'; \
        echo 'html_errors = Off'; \
    } > /usr/local/etc/php/conf.d/error-logging.ini

VOLUME /var/www/html

ENV WORDPRESS_VERSION 5.2.2
ENV WORDPRESS_SHA1 3605bcbe9ea48d714efa59b0eb2d251657e7d5b0

RUN set -ex; \
    curl -o wordpress.tar.gz -fSL "https://wordpress.org/wordpress-${WORDPRESS_VERSION}.tar.gz"; \
    echo "$WORDPRESS_SHA1 *wordpress.tar.gz" | sha1sum -c -; \
# upstream tarballs include ./wordpress/ so this gives us /usr/src/wordpress
    tar -xzf wordpress.tar.gz -C /usr/src/; \
    rm wordpress.tar.gz; \
    chown -R www-data:www-data /usr/src/wordpress

COPY docker-entrypoint.sh /usr/local/bin/

ENTRYPOINT ["docker-entrypoint.sh"]
CMD ["php-fpm"]

And I only modified the docker-compose.yml file for creating the Wordpress image with the mysql_pdo extension:

version: '3'

services:
    db_projects:
      container_name: ${CONTAINER_DB_NAME}
      image: mariadb:10.4
      restart: unless-stopped
      volumes:
        - ${DB_PATH}:/var/lib/mysql
      environment:
        MYSQL_ROOT_PASSWORD: ${MYSQL_ROOT_PASSWORD}
        MYSQL_DATABASE: ${MYSQL_DATABASE}
        MYSQL_USER: ${MYSQL_USER}
        MYSQL_PASSWORD: ${MYSQL_PASSWORD}

    wp_projects:
      depends_on:
        - db_projects
      container_name: ${CONTAINER_WP_NAME}
      #image: wordpress:latest
      build: ./wordpress
        #context: .
        #dockerfile: Custom-Wp-Dockerfile
      restart: unless-stopped
      volumes:
        - ${WP_CORE}:/var/www/html
        - ${WP_CONTENT}:/var/www/html/wp-content
        - ./conf.d/php.ini:/usr/local/etc/php/conf.d/php.ini
      environment:
        WORDPRESS_DB_HOST: ${CONTAINER_DB_NAME}:3306
        WORDPRESS_DB_NAME: ${MYSQL_DATABASE}
        WORDPRESS_DB_USER: ${MYSQL_USER}
        WORDPRESS_DB_PASSWORD: ${MYSQL_PASSWORD}
        WORDPRESS_TABLE_PREFIX: ${WORDPRESS_TABLE_PREFIX}
        VIRTUAL_HOST: ${DOMAINS}
        LETSENCRYPT_HOST: ${DOMAINS}
        LETSENCRYPT_EMAIL: ${LETSENCRYPT_EMAIL}
      logging:
        options:
          max-size: ${LOGGING_OPTIONS_MAX_SIZE:-200k}
    pma_projects:
      image: phpmyadmin/phpmyadmin
      restart: unless-stopped
      container_name: pma_projects
      links:
        - db_projects
      ports:
        - ${PMA_PORT}:80
      environment:
        #MYSQL_USERNAME: root
        #MYSQL_ROOT_PASSWORD: ${MYSQL_ROOT_PASSWORD}
        PMA_HOST: db_projects
        PMA_PORT: 3306
        #PMA_USER: ${MYSQL_USER}
        #PMA_PASSWORD: ${MYSQL_PASSWORD}
        PMA_ARBITRARY: 1
      depends_on:
        - wp_projects
        - db_projects

#   wpcli:
#     image: tatemz/wp-cli
#     volumes:
#       - ${WP_CORE}:/var/www/html
#       - ${WP_CONTENT}:/var/www/html/wp-content
#     depends_on:
#       - db
#     entrypoint: wp

networks:
    default:
       external:
         name: ${NETWORK}

After executing docker-compose up -d I get the following error:

[pathros@projects wp]$ sudo docker-compose up -d Building wp_projects Step 1/12 : FROM php:7.3-apache 7.3-apache: Pulling from library/php 1ab2bdfe9778: Pulling fs layer 1448c64389e0: Pulling fs layer 4b8a4e62b444: Pulling fs layer 9eb9d1e8e241: Waiting d20b2d19292c: Waiting 023060ea5930: Waiting a7fa99bc84ac: Waiting 084397ea0b0b: Waiting 27f2e3242e8a: Waiting c53d955b925a: Waiting 55a8a68dea39: Waiting b78786d44570: Waiting 69dd7e866b60: Waiting 2907cf87b0bb: Waiting ERROR: Service 'wp_projects' failed to build: error pulling image configuration: Get https://production.cloudflare.docker.com/registry-v2/docker/registry/v2/blobs/sha256/aa/aa4bdc74350b45a805ad9bdd39ec2cc38cd604a432e447497c3103ad0a8115d8/data?verify=1568225825-5P%2BOlgyxV6p%2FjAXyu%2BTLKCEU5RM%3D : EOF

Your wordpress image used in this stack is default image of Docker Hub and they have very detail documentation of how to install new PHP extension.

First we have to edit some changes on your docker-compose.yml file to make new wordpress custom build:

wordpress:
     depends_on:
       - db
     container_name: ${CONTAINER_WP_NAME}
     # image: wordpress:latest
     build: ./wordpress

Second, create a new file called Dockerfile and docker-entrypoint.sh of WordPress default image here , place it inside wordpress directory. Amend some magic code to wordpress/Dockerfile file:

RUN docker-php-ext-install pdo pdo_mysql

Now you have your custom Docker stack with PDO_MYSQL extension and able to run your backup process.

Your stack's config after edit: https://github.com/tdtgit/stackoverflow57447284

Feel free to comment if you need help.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM