Docker fails to enable php extensions - php

I am trying to install some php extensions all day but an error I do not understand occurs. Basically if I remove the install docker-php-ext-enable line everything seems to work normally (except my app that depends on them).
Dockerfile
FROM php:8.0-apache
RUN apt-get update && \
apt-get install -y unzip libcurl4-openssl-dev zlib1g-dev libpng-dev libxml2-dev libzip-dev
RUN a2enmod rewrite
RUN docker-php-ext-enable bcmath gd mysqli soap zip xml ctype curl fileinfo json
COPY idoit-1.16.2.zip /temp/idoit-1.16.2.zip
RUN unzip /temp/idoit-1.16.2.zip -d /var/www
RUN rm /temp/idoit-1.16.2.zip
COPY apache-vhost.conf /etc/apache2/sites-available/000-default.conf
# RUN chown -R www-data:www-data /var/www
CMD ["/usr/sbin/apache2ctl", "-D", "FOREGROUND"]
EXPOSE 80
Here is what I get when i run sudo docker build -t test .
Sending build context to Docker daemon 153.9MB
Step 1/23 : FROM php:8.0-apache
---> 1157b188bd87
Step 2/23 : RUN apt-get update && apt-get install -y unzip libcurl4-openssl-dev zlib1g-dev libpng-dev libxml2-dev libzip-dev
---> Using cache
---> aacd74715e3f
Step 3/23 : RUN a2enmod rewrite
---> Using cache
---> 1ab1cd3d1228
Step 4/23 : RUN docker-php-ext-enable fileinfo
---> Running in 7d8a84075a50
error: 'fileinfo' does not exist
usage: /usr/local/bin/docker-php-ext-enable [options] module-name [module-name ...]
ie: /usr/local/bin/docker-php-ext-enable gd mysqli
/usr/local/bin/docker-php-ext-enable pdo pdo_mysql
/usr/local/bin/docker-php-ext-enable --ini-name 0-apc.ini apcu apc
Possible values for module-name:
opcache.so sodium.so
Some of the above modules are already compiled into PHP; please check
the output of "php -i" to see which modules are already loaded.
Any ideas?

Related

PHP GD no webp support in docker

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

Docker / Symfony / MongoDB - Cannot install mongodb with PHP 5.6 FPM

I'm not able to install mongodb extension using php:5.6-fpm image.
What's wrong with my Dockerfile configuration ?
FROM php:5.6-fpm
RUN apt-get update \
&& mkdir -p /usr/share/man/man1 \
&& mkdir -p /usr/share/man/man7 \
&& apt-get install -y --no-install-recommends vim curl debconf subversion git apt-transport-https apt-utils \
build-essential locales acl mailutils wget zip unzip htop vim \
gnupg gnupg1 gnupg2 \
libmemcached-dev zlib1g-dev \
libcurl4-openssl-dev pkg-config libssl-dev libicu-dev g++
RUN docker-php-ext-configure intl
RUN docker-php-ext-install pdo pdo_mysql zip intl
RUN pecl install mongodb
RUN docker-php-ext-enable mongodb
COPY php.ini /usr/local/etc/php/conf.d/php.ini
...
...
I have the following error when executing docker-compose build
Step 5/18 : RUN pecl install mongodb
---> Running in 5cd13b1b969c
WARNING: channel "pecl.php.net" has updated its protocols, use "pecl channel-update pecl.php.net" to update
pecl/mongodb requires PHP (version >= 7.0.0, version <= 7.99.99), installed version is 5.6.40
No valid packages found
install failed
Solution:
RUN pecl install mongodb-1.7.4

Can't build php docker image [duplicate]

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/

Install / Configure SQL Server PDO driver for PHP docker image

I have a simple docker file, as follows:
FROM php:7.2-apache
COPY src/ /var/www/html/
Normally to install drivers for Mongo or MySQL connectivity I would do so by adding something like the below to the dockerfile:
docker-php-ext-install mongo
On this occasion I want to connect my php application to a SQL Server database, and I understand the best way to do this for php 7.x is by using the PDO driver, however I am unfamiliar with how to do configure this in the dockerfile.
I've tried doing a pecl install, like adding:
RUN pecl install sqlsrv pdo_sqlsrv
However this fails with a combination of errors that do not seem to point me in the right direction.
I'm just looking for a simple way to get this done in a dockerfile or by using docker run.
For added info, here's the error I'm getting:
/tmp/pear/temp/sqlsrv/shared/xplat.h:30:17: fatal error: sql.h: No such file or directory
#include <sql.h>
^
compilation terminated.
Makefile:194: recipe for target 'conn.lo' failed
make: *** [conn.lo] Error 1
ERROR: `make' failed
The command '/bin/sh -c pecl install sqlsrv pdo_sqlsrv && docker-php-ext-enable pdo_sqlsrv' returned a non-zero code: 1
Thanks all
I have created a docker file for this exact purpose:
FROM php:7.3-apache
ENV ACCEPT_EULA=Y
RUN apt-get update && apt-get install -y gnupg2
RUN curl https://packages.microsoft.com/keys/microsoft.asc | apt-key add -
RUN curl https://packages.microsoft.com/config/ubuntu/20.04/prod.list > /etc/apt/sources.list.d/mssql-release.list
RUN apt-get update
RUN ACCEPT_EULA=Y apt-get -y --no-install-recommends install msodbcsql17 unixodbc-dev
RUN pecl install sqlsrv
RUN pecl install pdo_sqlsrv
RUN docker-php-ext-enable sqlsrv pdo_sqlsrv
COPY . /var/www/html/
Enjoy!
Did you get an answer to this? I got it working with the following steps. (The unixodbc-dev package should get you past the pecl install.)
in the Docker file:
RUN apt-get -y install unixodbc-dev
RUN pecl install sqlsrv pdo_sqlsrv
And then you have to add some changes to php.ini to enable sqlserver.
get a local copy of php.ini and add these lines:
extension=pdo_sqlsrv.so
extension=sqlsrv.so
Then copy your local php.ini into the docker image (my file is in a local "config" folder).
in the Docker file:
COPY config/php.ini /usr/local/etc/php/
My docker config:
###############
# MSSQL support
###############
RUN apt-get update \
&& apt-get install -y gpg unixodbc unixodbc-dev \
&& docker-php-ext-install pdo pdo_mysql \
&& pecl install sqlsrv pdo_sqlsrv
# ------------ Install MS SQL client deps ------------ #
# adding custom MS repository
RUN curl https://packages.microsoft.com/keys/microsoft.asc | apt-key add -
RUN curl https://packages.microsoft.com/config/debian/9/prod.list > /etc/apt/sources.list.d/mssql-release.list
# install SQL Server drivers and tools
RUN apt-get update && ACCEPT_EULA=Y apt-get install -y msodbcsql17
RUN echo 'export PATH="$PATH:/opt/mssql-tools/bin"' >> ~/.bashrc
RUN /bin/bash -c "source ~/.bashrc"
# Debian 9 msodbcsql : https://packages.microsoft.com/debian/9/prod/pool/main/m/msodbcsql17/
RUN wget https://packages.microsoft.com/debian/9/prod/pool/main/m/msodbcsql17/msodbcsql17_17.4.2.1-1_amd64.deb
RUN ACCEPT_EULA=Y dpkg -i msodbcsql17_17.4.2.1-1_amd64.deb
RUN apt-get -y install locales
RUN echo "en_US.UTF-8 UTF-8" > /etc/locale.gen
RUN locale-gen
RUN echo "extension=sqlsrv.so" >> /usr/local/etc/php/conf.d/docker-php-ext-sqlsrv.ini
RUN echo "extension=pdo_sqlsrv.so" >> /usr/local/etc/php/conf.d/docker-php-ext-pdo-sqlsrv.ini
# -------------- END MSSQL -------------------------------- #
FROM php:7.4.0-apache
ENV ACCEPT_EULA=Y
RUN apt-get update && apt-get install -y gnupg2
RUN curl https://packages.microsoft.com/keys/microsoft.asc | apt-key add -
RUN curl https://packages.microsoft.com/config/ubuntu/20.04/prod.list > /etc/apt/sources.list.d/mssql-relea`enter code here`se.list
RUN apt-get update
RUN ACCEPT_EULA=Y apt-get -y --no-install-recommends install msodbcsql17 unixodbc-dev
RUN pecl install sqlsrv
RUN pecl install pdo_sqlsrv
RUN docker-php-ext-install pdo pdo_mysql
RUN docker-php-ext-enable sqlsrv pdo_sqlsrv pdo pdo_mysql
COPY index.php /var/www/html/

Cannot load PHP class when running Symfony command

I would appreciate any help I can get with following issue.
I've set up Symfony Messenger to use AMQP and RabbitMQ. I can dispatch message and make use of AMQPConnection within my project.
But when I try to consume the message I get following:
$ php bin/console messenger:consume-messages amqp
Attempted to load class "AMQPConnection" from the global namespace.
Did you forget a "use" statement for "PhpAmqpLib\Connection\AMQPConnection"?
The console command calls a method within AmqpFactory.php
public function createConnection(array $credentials): \AMQPConnection
{
return new \AMQPConnection($credentials);
}
So when I run the project from the browser, everything works fine. I can use AMQPConnection and all. But when running from terminal, it cannot find the AMQPConnection class.
From within my composer.json I also have the amqplib installed
"php-amqplib/php-amqplib": "^2.7",
I use Docker and the Dockerfile contains:
FROM php:7-apache
RUN usermod -u 1000 www-data &&\
a2dissite 000-default &&\
apt-get update &&\
apt-get install -y \
zlib1g-dev \
libicu-dev \
g++ \
libfreetype6-dev \
libssh-dev \
libjpeg62-turbo-dev \
libmcrypt-dev \
librabbitmq-dev \
libpng-dev &&\
docker-php-ext-configure intl &&\
docker-php-ext-configure gd --with-freetype-dir=/usr/include/ --with-jpeg-dir=/usr/include/ &&\
docker-php-ext-install -j$(nproc) gd pdo_mysql intl opcache zip pcntl exif bcmath sockets &&\
a2enmod rewrite
RUN pecl install amqp \
&& docker-php-ext-enable amqp
COPY docker/apache2.conf /etc/apache2/apache2.conf
WORKDIR /var/www/project
UPDATE!
I've printed the phpinfo() and when dispatching the message I have version 7.2.8 and when executing the terminal command I have 7.2.7. So terminal is not using the Docker instance of PHP when executing the command.
Solved this, finally. I had no idea I had to go via Docker to run this command. This worked for me:
docker exec -ti container_name sh -c "cd /var/www/project/ && php bin/console messenger:consume-messages amqp"
When using Docker, Symfony commands needs to be executed inside needed container.
The problem come from trying to execute php from the local host:
$ php bin/console messenger:consume-messages amqp
whereas the local host does not have the necessary dependencies, RabbitMQ in this case.
Instead the command should be run using the right container:
$ docker exec -ti container_name sh -c "cd /var/www/project/ && php bin/console messenger:consume-messages amqp"
container_name being the name of the container having the RabbitMQ dependencies.
You are missing package librabbitmq4 in your Docker container. Add RUN apt-get update --fix-missing && apt-get update && apt-get install php-amqp to your Dockerfile and rebuild the image.

Categories