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.
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
Related
In order to resolve an issue, I am now trying install the mysql pdo via
docker-php-ext-install
as pointed out in the README of the php image.
Yet my call fails stating:
Libraries have been installed in:
/usr/src/php/ext/mysqli/modules
If you ever happen to want to link against installed libraries
in a given directory, LIBDIR, you must either use libtool, and
specify the full pathname of the library, or use the `-LLIBDIR'
flag during linking and do at least one of the following:
- add LIBDIR to the `LD_LIBRARY_PATH' environment variable
during execution
- add LIBDIR to the `LD_RUN_PATH' environment variable
during linking
- use the `-Wl,--rpath -Wl,LIBDIR' linker flag
- have your system administrator add LIBDIR to `/etc/ld.so.conf'
See any operating system documentation about shared libraries for
more information, such as the ld(1) and ld.so(8) manual pages.
----------------------------------------------------------------------
Build complete.
Don't forget to run 'make test'.
Installing shared extensions: /usr/local/lib/php/extensions/no-debug-non-zts-20131226/
Installing header files: /usr/local/include/php/
find . -name \*.gcno -o -name \*.gcda | xargs rm -f
find . -name \*.lo -o -name \*.o | xargs rm -f
find . -name \*.la -o -name \*.a | xargs rm -f
find . -name \*.so | xargs rm -f
find . -name .libs -a -type d|xargs rm -rf
rm -f libphp.la modules/* libs/*
+ cd /usr/src/php/ext/mysqlnd
+ phpize
Cannot find config.m4.
Make sure that you run '/usr/local/bin/phpize' in the top level source directory of the module
ERROR: Service 'phlaconapp' failed to build: The command '/bin/sh -c docker-php-ext-install mysqli mysqlnd pdo pdo_mysql zip' returned a non-zero code: 1
This is my docker-compose.yml:
phlaconapp:
hostname: phaclonapp
dockerfile: Dockerfile
build: ./
ports:
- "1080:80"
- "1043:433"
environment:
TERM: xterm-color
ENVIRONMENT: dev
volumes:
- ./:/var/www/html/
links:
- mysql
mysql:
image: mysql:5.6
volumes:
- ./docker/mysql.d:/etc/mysql/conf.d
ports: ["3306:3306"]
environment:
MYSQL_ROOT_PASSWORD: 'root'
This is my Dockerfile:
FROM php:5.6-apache
RUN php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');" && \
php -r "if (hash_file('SHA384', 'composer-setup.php') === '070854512ef404f16bac87071a6db9fd9721da1684cd4589b1196c3faf71b9a2682e2311b36a5079825e155ac7ce150d') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;" && \
php composer-setup.php && \
php -r "unlink('composer-setup.php');"
RUN apt-get update && \
apt-get install vim git -y
RUN docker-php-ext-install mysqli mysqlnd pdo pdo_mysql zip
RUN cd / && \
git clone --depth=1 git://github.com/phalcon/cphalcon.git && \
cd cphalcon/build && \
./install
RUN echo "extension=phalcon.so" > /usr/local/etc/php/conf.d/phalcon.ini
RUN a2enmod rewrite
and running docker-compose build won't finish.
I had the same problem a while ago. I started a container and typed the ext-install command into this container. Once I found all the dependencies, I wrote them into the Dockerfile.
Example:
RUN apt-get update && apt-get install -y \
libmcrypt-dev \
&& docker-php-ext-install -j$(nproc) mcrypt
There is a dependency that libmcrypt-dev needed before you can run docker-php-ext-install mcrypt
I've checked my older Dockerfiles and found something which might help you
FROM php:5.6-apache
RUN apt-get update && apt-get install -y \
libfreetype6-dev \
libjpeg62-turbo-dev \
libmcrypt-dev \
libpng12-dev \
libicu-dev \
libxml2-dev \
vim \
wget \
unzip \
git \
&& docker-php-ext-install -j$(nproc) iconv intl xml soap mcrypt opcache pdo pdo_mysql mysqli mbstring \
&& docker-php-ext-configure gd --with-freetype-dir=/usr/include/ --with-jpeg-dir=/usr/include/ \
&& docker-php-ext-install -j$(nproc) gd
RUN a2enmod rewrite && mkdir /composer-setup && wget https://getcomposer.org/installer -P /composer-setup && php /composer-setup/installer --install-dir=/usr/bin && rm -Rf /composer-setup && curl -LsS https://symfony.com/installer -o /usr/local/bin/symfony && chmod a+x /usr/local/bin/symfony
# Create symlink for default conf
RUN ln -s /etc/apache2/sites-available/000-default.conf /etc/apache2/sites-enabled/000-default.conf && mkdir /composer-setup && wget https://getcomposer.org/installer -P /composer-setup && php /composer-setup/installer --install-dir=/usr/bin && rm -Rf /composer-setup && curl -LsS https://symfony.com/installer -o /usr/local/bin/symfony && chmod a+x /usr/local/bin/symfony
RUN docker-php-ext-install mbstring pdo pdo_mysql \
That code can do install any extension you want in this case mysql pdp driver but the Dockerfile should have base of FROM php:7.1.8-apache
The 2019 way and probably the 2020 way of installing memcached to your Docker PHP container is the way described on https://hub.docker.com/_/php
FROM php:latest
RUN pecl install memcached \
&& docker-php-ext-enable memcached
FROM php:5.6-cli
RUN apt-get update && apt-get install -y libmemcached-dev zlib1g-dev \
&& pecl install memcached-2.2.0 \
&& docker-php-ext-enable memcached
Seems to be a bug in phpize (https://bugs.php.net/bug.php?id=53571).
I added the following to docker-php-ext-configure:
/usr/local/bin # diff -u docker-php-ext-configure.bak docker-php-ext-configure
--- docker-php-ext-configure.bak
+++ docker-php-ext-configure
## -54,5 +54,6 ##
set -x
cd "$ext"
+[[ ! -f "config.m4" && -f "config0.m4" ]] && mv config0.m4 config.m4
phpize
./configure "$#"
Alternatively, you can use this excellent helper to install the needed libs automatically for you.
https://github.com/mlocati/docker-php-extension-installer
You only need to list the extensions you want like this:
FROM php:8.2-fpm-alpine
ADD https://github.com/mlocati/docker-php-extension-installer/releases/latest/download/install-php-extensions /usr/local/bin/
RUN chmod +x /usr/local/bin/install-php-extensions; \
install-php-extensions mysqli mysqlnd pdo pdo_mysql zip
Take a look at its GitHub page to see all options available to use.
I always used GD to manipulate webp normally in my local environment, but when attempting to test my scripts in docker environment, i get "Webp format is not supported by PHP installation." error. I am using latest php version as in showed in my dockerfile below:
FROM php:8-fpm
# Arguments defined in docker-compose.yml
ARG user
ARG uid
# Install system dependencies
RUN apt-get update && apt-get install -y \
git \
curl \
libpng-dev \
libonig-dev \
libxml2-dev \
zip \
unzip \
pngquant
# Clear cache
RUN apt-get clean && rm -rf /var/lib/apt/lists/*
# Install PHP extensions
RUN docker-php-ext-install pdo_mysql mbstring exif pcntl bcmath gd
# Get latest Composer
COPY --from=composer:latest /usr/bin/composer /usr/bin/composer
# Create system user to run Composer and Artisan Commands
RUN useradd -G www-data,root -u $uid -d /home/$user $user
RUN mkdir -p /home/$user/.composer && \
chown -R $user:$user /home/$user
# Set working directory
WORKDIR /var/www
USER $user
# php.ini
COPY ./docker-compose/php/php.ini /usr/local/etc/php/
What i am missing?
You need to install libwebp-dev and configure gd lib to support it:
RUN apt-get update && ... \
apt-get install -y libwebp-dev && \
docker-php-ext-configure gd --with-webp;
The the examples here : https://github.com/docker-library/docs/tree/master/php#how-to-install-more-php-extensions
I am building an app (PHP/Laravel) that is supposed to be deployed on Google's App Engine. One of the components of the app is to be able to connect to an MSSQL server. Everything worked fine when I was debugging it, but as soon as I deployed it to the App Engine - guess what? It does not work (error: could not find driver).
I went through the Google documentation and I found out that the MSSQL drivers (pdo_sqlsrv, sqlsrv) are not enabled nor available in the standard environment. I checked the flexible environment, but that's the same. The difference is that I can use my own runtime using Dockerfile.
I changed two lines of my app.yaml in the root directory:
runtime: custom
env: flex
Then I created my Dockerfile also in the root directory that was supposed to install sqlsrv and pdo_sqlsrv using PECL and enable it:
FROM gcr.io/google-appengine/php72:latest
ARG COMPOSER_FLAGS='--prefer-dist --ignore-platform-reqs --optimize-autoloader'
ENV COMPOSER_FLAGS=${COMPOSER_FLAGS}
ENV SWOOLE_VERSION=4.3.4
ENV DOCUMENT_ROOT=/app/public
ENV ACCEPT_EULA=Y
COPY . $APP_DIR
RUN apt-get update -y \
&& curl https://packages.microsoft.com/keys/microsoft.asc | apt-key add -\
&& curl https://packages.microsoft.com/config/ubuntu/16.04/prod.list > /etc/apt/sources.list.d/mssql-release.list \
&& apt-get update -y \
&& apt-get install -y \
unzip \
autoconf \
build-essential \
libmcrypt-dev \
libmpdec-dev \
libpq-dev \
unixodbc-dev \
msodbcsql17 \
mssql-tools \
php-common \
&& apt-get update \
&& pecl install \
decimal \
sqlsrv \
pdo_sqlsrv \
xdebug \
&& apt-get update \
&& phpenmod sqlsrv pdo_sqlsrv \
&& curl -o /tmp/swoole.tar.gz https://github.com/swoole/swoole-src/archive/v$SWOOLE_VERSION.tar.gz -L \
&& tar zxvf /tmp/swoole.tar.gz \
&& cd swoole-src* \
&& phpize \
&& ./configure \
--enable-coroutine \
--enable-async-redis \
--enable-coroutine-postgresql \
--enable-sqlsrv=static --with-pdo_sqlsrv=static \
&& make \
&& make install \
&& chown -R www-data.www-data $APP_DIR \
&& /build-scripts/composer.sh;
ENTRYPOINT ["/build-scripts/entrypoint.sh"]
CMD ["/usr/bin/supervisord", "-c", "/etc/supervisor/supervisord.conf"]
EXPOSE 8080
I also have my own php.ini with two lines in the root directory:
extension = pdo_sqlsrv.so
extension = sqlsrv.so
According to the Google documentation, having this file in the root of an app will extend/replace their default php.ini with my configuration. However, I only found this statement in the docs for non-custom runtimes. I tested it out by changing the value of display_errors and then phpinfo(). The display_errors was still set to the default value and get_loaded_extensions() didn't display sqlsrv nor pdo_sqlsrv.
I checked the build-log and it seems that the drivers were properly installed, because in the 3714 lines I found:
Installing '/opt/php72/lib/x86_64-linux-gnu/extensions/no-debug-non-zts-20170718/sqlsrv.so'
install ok: channel://pecl.php.net/sqlsrv-5.8.1
.....
Installing '/opt/php72/lib/x86_64-linux-gnu/extensions/no-debug-non-zts-20170718/pdo_sqlsrv.so'
install ok: channel://pecl.php.net/pdo_sqlsrv-5.8.1
.....
configuration option "php_ini" is not set to php.ini location
You should add "extension=sqlsrv.so" to php.ini
configuration option "php_ini" is not set to php.ini location
You should add "extension=pdo_sqlsrv.so" to php.ini
Does anybody have any experience with this, please? What do I need to change in the Dockerfile to make Google App Engine enable the PHP extensions?
TL;DR: Add COPY php.ini /opt/php/lib/conf.d/ to Dockerfile.
Google documentation for GAE Standard environment says that you can place php.ini into the root directory, but I didn't find anything like that about Flexible env. Indeed, if you check Configuration File in phpinfo, and related. fields, they show other paths they're looking for php.ini, so you need to place the file there.
When I try that, the custom php.ini is loaded and allows overwriting display_errors, which you mentioned didn't work for you.
Multi-stage build
To avoid shipping C compiler and other build tools to production, which is wasteful and may slow down deployment of your app, you should also use docker's multi-stage build. Basically, you'll build the extensions in one "builder" container and copy the compiled result to the production container.
You Dockerfile will look sth like this:
FROM gcr.io/google-appengine/php72:latest AS builder
RUN apt-get update -y \
&& apt-get install -y \
unzip \
autoconf \
build-essential \
libmcrypt-dev \
libmpdec-dev \
libpq-dev \
unixodbc-dev \
php-common \
&& pecl install \
sqlsrv \
pdo_sqlsrv
FROM gcr.io/google-appengine/php72:latest
# Copy extensions from builder above
ENV PHP_EXT_DIR=/opt/php/lib/x86_64-linux-gnu/extensions/no-debug-non-zts-20170718/
COPY --from=builder $PHP_EXT_DIR/sqlsrv.so $PHP_EXT_DIR/
COPY --from=builder $PHP_EXT_DIR/pdo_sqlsrv.so $PHP_EXT_DIR/
# Install runtime dependencies
ENV ACCEPT_EULA=Y
RUN curl https://packages.microsoft.com/keys/microsoft.asc | apt-key add -\
&& curl https://packages.microsoft.com/config/ubuntu/16.04/prod.list > /etc/apt/sources.list.d/mssql-release.list \
&& apt-get update -y \
&& apt-get install -y \
msodbcsql17 \
mssql-tools
...
This question already has answers here:
ADD failed : No such file/Directory while building docker image
(3 answers)
Closed 2 years ago.
I got this error when building docker php image
Step 13/25 : ADD php.ini /usr/local/etc/php/php.ini
ERROR: Service 'phpt3' failed to build: ADD failed: stat
/var/lib/docker/tmp/docker-builder310748204/php.ini: no
such file or directory
Below is the docker file:
FROM php:7.3-fpm
# install the PHP extensions we need
RUN apt-get update \
&& apt-get install -y --no-install-recommends msmtp mailutils vim curl debconf subversion git apt-transport-https apt-utils \
build-essential locales acl mailutils wget nodejs \
gnupg gnupg1 gnupg2 \
zlib1g-dev zlib1g-dev libicu-dev g++ \
sudo
# Install GD
RUN apt-get install -y libfreetype6-dev libjpeg62-turbo-dev libpng-dev
RUN docker-php-ext-configure gd --with-freetype-dir=/usr/include/ --with-jpeg-dir=/usr/include/
RUN docker-php-ext-install -j$(nproc) gd
RUN docker-php-ext-configure gd --with-freetype-dir=/usr/include/ --with-jpeg-dir=/usr/include/
RUN docker-php-ext-install gd
# MYSQLI
RUN docker-php-ext-install mysqli && docker-php-ext-enable mysqli
# Install ext-zip
RUN apt-get install -y unzip libzip-dev
RUN docker-php-ext-install zip
RUN docker-php-ext-configure intl
RUN docker-php-ext-install pdo_mysql json calendar intl
ADD php.ini /usr/local/etc/php/php.ini
COPY additionnal.ini /usr/local/etc/php/conf.d/
COPY php-fpm-pool.conf /usr/local/etc/php/pool.d/www.conf
RUN rm -rf /var/lib/apt/lists/* \
echo "en_US.UTF-8 UTF-8" > /etc/locale.gen && \
echo "fr_FR.UTF-8 UTF-8" >> /etc/locale.gen && \
locale-gen
# Install Composer
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
RUN composer --version
# set up sendmail config, see http://linux.die.net/man/5/ssmtp.conf for options
RUN echo "hostname=localhost.localdomain" > /etc/msmtp/msmtp.conf
RUN echo "mailhub=maildevt3" >> /etc/msmtp/msmtp.conf
# The above 'maildevt3' is the name you used for the link command
# in your docker-compose file or docker link command.
# Docker automatically adds that name in the hosts file
# of the container you're linking MailDev to.
# Set up php sendmail config
RUN echo "sendmail_path=sendmail -i -t" >> /usr/local/etc/php/conf.d/php-sendmail.ini
# Fully qualified domain name configuration for sendmail on localhost.
# Without this sendmail will not work.
# This must match the value for 'hostname' field that you set in ssmtp.conf.
RUN echo "localhost localhost.localdomain" >> /etc/hosts
WORKDIR /var/www/
EXPOSE 9000
CMD ["php-fpm"]
Can anyone help me to overcome this bug.
I'm doing this tutorial
https://passions.miary.dev/2019/08/30/docker-maildev-fr/
It looks like the image installer does not have the rights to write to the installation directory.
-> How to fix:
ADD failed : No such file/Directory while building docker image
If that doesn't work: test if the folder, which is shown in the error exists.
Give enough permissions to the directory with chmod -> https://wiki.ubuntuusers.de/chmod/
This question already has answers here:
Fatal error: Class 'ZipArchive' not found in
(25 answers)
Closed 3 months ago.
I have the following error on my docker machine/instance:
Class 'ZipArchive' not found
Here is my Dockerfile:
FROM php:7.2-alpine
RUN docker-php-ext-install sockets pdo_mysql
RUN docker-php-ext-install -j$(nproc) \
zip
ADD consumer /opt/craft/app/
ADD app.tar.gz /opt/craft/app
CMD /opt/craft/app/consumer
When I sh in to the container via docker-run, I can do php -m:
[PHP Modules]
Core
ctype
curl
date
dom
fileinfo
filter
ftp
hash
iconv
json
libxml
mbstring
mysqlnd
openssl
pcre
PDO
pdo_mysql
pdo_sqlite
Phar
posix
readline
Reflection
session
SimpleXML
sockets
sodium
SPL
sqlite3
standard
tokenizer
xml
xmlreader
xmlwriter
zlib
zip is not there. Is it supposed to be there? I have also tried doing:
/opt/craft/app # apk add zip
OK: 17 MiB in 29 packages
/opt/craft/app # php -m
But zip still isn't available and I still get the same output error ziparchive not found.
I'm quite new to docker and installing php modules by myself.
How do I get ZipArchive class installed? (Ideally through dockerfile).
Actually when I faced Laravel excel problem on php-fpm 7.4 on docker, I find your question. And this answer
RUN apk update \
&& apk upgrade \
&& apk add zlib-dev \
&& docker-php-ext-configure zip --with-zlib-dir=/usr \
&& docker-php-ext-install zip
don't working forme
I think this Dockerfile works fine for you
FROM php:7.4-fpm
# Arguments defined in docker-compose.yml
ARG user
ARG uid
# Install system dependencies
RUN apt-get update && apt-get install -y \
git \
curl \
libpng-dev \
libonig-dev \
libxml2-dev \
zip \
unzip
RUN apt-get update && \
apt-get install -y \
libzip-dev \
&& docker-php-ext-install zip
# Clear cache
RUN apt-get clean && rm -rf /var/lib/apt/lists/*
# Install PHP extensions
RUN docker-php-ext-install pdo_mysql mbstring exif pcntl bcmath gd
# Get latest Composer
COPY --from=composer:latest /usr/bin/composer /usr/bin/composer
# Create system user to run Composer and Artisan Commands
RUN useradd -G www-data,root -u $uid -d /home/$user $user
RUN mkdir -p /home/$user/.composer && \
chown -R $user:$user /home/$user
# Set working directory
WORKDIR /var/www
USER $user
try replace
RUN docker-php-ext-install -j$(nproc) \
zip
with
RUN apk update \
&& apk upgrade \
&& apk add zlib-dev \
&& docker-php-ext-configure zip --with-zlib-dir=/usr \
&& docker-php-ext-install zip
in Dockerfile
I tried it and it worked.