Jonas Van Bogaert
Jonas Van Bogaert

Reputation: 339

Assign specific PHP version to Drupal (Docker containers)

Is there a way to assign a specific PHP version to a drupal Docker container?

I have a docker-compose file to link Drupal with MariaDB. Everything works so far, but I want to assign a specific PHP version for migration purposes.

Upvotes: 1

Views: 903

Answers (1)

Tarun Lalwani
Tarun Lalwani

Reputation: 146530

Since you are using the official image, they only come with specific php versions. Consider the below docker file of the official image

https://github.com/docker-library/drupal/blob/a8e09f524b89b61534f376e45b885d433d867c88/7/apache/Dockerfile

# from https://www.drupal.org/requirements/php#drupalversions
FROM php:7.0-apache

RUN a2enmod rewrite

# install the PHP extensions we need
RUN set -ex \
    && buildDeps=' \
        libjpeg62-turbo-dev \
        libpng12-dev \
        libpq-dev \
    ' \
    && apt-get update && apt-get install -y --no-install-recommends $buildDeps && rm -rf /var/lib/apt/lists/* \
    && docker-php-ext-configure gd \
        --with-jpeg-dir=/usr \
        --with-png-dir=/usr \
    && docker-php-ext-install -j "$(nproc)" gd mbstring pdo pdo_mysql pdo_pgsql zip \
# PHP Warning:  PHP Startup: Unable to load dynamic library '/usr/local/lib/php/extensions/no-debug-non-zts-20151012/gd.so' - libjpeg.so.62: cannot open shared object file: No such file or directory in Unknown on line 0
# PHP Warning:  PHP Startup: Unable to load dynamic library '/usr/local/lib/php/extensions/no-debug-non-zts-20151012/pdo_pgsql.so' - libpq.so.5: cannot open shared object file: No such file or directory in Unknown on line 0
    && apt-mark manual \
        libjpeg62-turbo \
        libpq5 \
    && apt-get purge -y --auto-remove $buildDeps

WORKDIR /var/www/html

# https://www.drupal.org/node/3060/release
ENV DRUPAL_VERSION 7.56
ENV DRUPAL_MD5 5d198f40f0f1cbf9cdf1bf3de842e534

RUN curl -fSL "https://ftp.drupal.org/files/projects/drupal-${DRUPAL_VERSION}.tar.gz" -o drupal.tar.gz \
    && echo "${DRUPAL_MD5} *drupal.tar.gz" | md5sum -c - \
    && tar -xz --strip-components=1 -f drupal.tar.gz \
    && rm drupal.tar.gz \
    && chown -R www-data:www-data sites

Now create a copy of this. And change the top FROM php:7.0-apache to the the version you are interested in. You can see all the available versions below

https://hub.docker.com/r/library/php/tags/

And then rebuild the image to create your own drupal image with specific php version

Upvotes: 2

Related Questions