PHP:8-Apache Custom-image docker-compose errors over errors

Hello,
I’m currently trying to build Custom images under docker-compose.
I get a lot of error messages and no matter what I install, there are errors.
I suspect something else is wrong with my approach

Maybe someone can help me. I’m still brand new among Docker users

My System is
Raspberry Pi 4
Raspberry original image

PRETTY_NAME="Debian GNU/Linux 11 (bullseye)"
NAME="Debian GNU/Linux"
VERSION_ID="11"
VERSION="11 (bullseye)"
VERSION_CODENAME=bullseye
ID=debian
HOME_URL="https://www.debian.org/"
SUPPORT_URL="https://www.debian.org/support"
BUG_REPORT_URL="https://bugs.debian.org/"

i have only a default Raspberry debian 64Bit image i dont have any apache or php instaled
thats mean i don’t have any folders created already on my system maybe what the instaltions need

There are my folders and docker-volume

/home/grobot/docker
looks like that


grobot@GRobotServer:~/docker $ ls -la
insgesamt 40
drwxr-xr-x 9 grobot   grobot   4096 21. Feb 23:19 .
drwxr-xr-x 6 grobot   grobot   4096 21. Feb 21:04 ..
drwxrwxrwx 2 www-data www-data 4096   21. Feb 22:03 apache
drwxr-xr-x 2 grobot   grobot   4096             21. Feb 23:19 codeserver
-rw-r--r-- 1 grobot   grobot    849                 21. Feb 23:23 docker-compose.yml
drwxr-xr-x 3 root     root     4096                 21. Feb 19:15 influxDb
drwxr-xr-x 2 grobot   grobot   4096              21. Feb 21:04 lamp
drwxr-xr-x 3 root     root     4096                 21. Feb 19:15 mariadb
drwxr-xr-x 3 root     root     4096                 21. Feb 19:14 php
drwxr-xr-x 6 www-data www-data 4096       21. Feb 19:14 www

Here is my docker-compose.yaml

ersion: "3.9"

volumes: 
  dbdata:
  code:

services: 
  apache:
    container_name: apache
    build: apache
    ports: 
      - 80:80
      - 443:443
    volumes: 
      - code:./www/html/
      - ./apache/php-ini-overrides.ini:/usr/local/etc/php/conf.d/php-ini-overrides.ini
  codeserver:
    container_name: codeserver
    image: ghcr.io/linuxserver/openssh-server
    environment:
      - PASSWORD_ACCESS=true 
      - USER_PASSWORD=secret
      - USER_NAME=ssh
      - PUID=1000
      - PGID=33
    ports: 
      - 22:2222
    volumes:
      - code:./www/html/   
  mariadb:
    image: mariadb:latest
    container_name: mariadb
    ports: 
      - 3306:3306
    environment: 
      - MYSQL_USER=root
      - MYSQL_PASSWORD=secret
      - MYSQL_ROOT_PASSWORD=secret
    restart: always
    volumes: 
      - dbdata:/var/lib/mysql

there is my Dockerfile

i try there a lot of samples… but i get only errors

FROM php:8-apache

LABEL maintainer "a210611@gmail.com"
LABEL description "HA_Webserver_Apache2"

# Umgebungsvariablen und Zeitzonen festlegen

#ENV TZ"EUROPE/BERLIN" \
#    APACHE_RUN_USER=www-data \
#    APACHE_RUN_GROUP=www-data \
#    APACHE_LOG_DIR=/var/log/apache2

RUN pear config-set php_ini "$PHP_INI_DIR"
# Patch wegen freetype fehler
RUN apt-get update \
&& apt-get install -y \
&& pecl install xdebug  \
&& 2enmod rewrite \ 
&& a2enmod headers

# RUN docker-php-ext-configure gd --with-freetype-dir --with-jpeg-dir=/usr/include/
RUN docker-php-ext-configure gd --with-freetype --with-jpeg 
RUN docker-php-ext-install opcache gd pdo_mysql zip 
RUN docker-php-ext-enable opcache gd xdebug zip 

RUN echo "ServerName localhost" >> ./apache/apache2.conf
# RUN service apache2 restart
# Startkommando
CMD ["/usr/sbin/apache2ctl", "-D", "FOREGROUND"]

There is my terminal output
i try to run docker-composer witzh this commands

docker-compose up -d
or
sudo docker-compose up

both not work

0 160.0 Libraries have been installed in:
#0 160.0    /tmp/pear/temp/pear-build-defaultuser81DoC2/xdebug-3.2.0/modules
#0 160.0
#0 160.0 If you ever happen to want to link against installed libraries
#0 160.0 in a given directory, LIBDIR, you must either use libtool, and
#0 160.0 specify the full pathname of the library, or use the `-LLIBDIR'
#0 160.0 flag during linking and do at least one of the following:
#0 160.0    - add LIBDIR to the `LD_LIBRARY_PATH' environment variable
#0 160.0      during execution
#0 160.0    - add LIBDIR to the `LD_RUN_PATH' environment variable
#0 160.0      during linking
#0 160.0    - use the `-Wl,--rpath -Wl,LIBDIR' linker flag
#0 160.0    - have your system administrator add LIBDIR to `/etc/ld.so.conf'
#0 160.0
#0 160.0 See any operating system documentation about shared libraries for
#0 160.0 more information, such as the ld(1) and ld.so(8) manual pages.
#0 160.0 ----------------------------------------------------------------------
#0 160.0
#0 160.1 Build complete.
#0 160.1 Don't forget to run 'make test'.
#0 160.1
#0 160.1 running: make INSTALL_ROOT="/tmp/pear/temp/pear-build-defaultuser81DoC2/install-xdebug-3.2.0" install
#0 160.1 Makefile:245: warning: overriding recipe for target 'test'
#0 160.1 Makefile:136: warning: ignoring old recipe for target 'test'
#0 160.4 Installing shared extensions:     /tmp/pear/temp/pear-build-defaultuser81DoC2/install-xdebug-3.2.0/usr/local/lib/php/extensions/no-debug-non-zts-20220829/
#0 160.6
#0 160.7 shtool:echo:Warning: unable to determine terminal sequence for bold mode
#0 160.8   +----------------------------------------------------------------------+
#0 160.8   |                                                                      |
#0 160.8   |   INSTALLATION INSTRUCTIONS                                          |
#0 160.8   |   =========================                                          |
#0 160.8   |                                                                      |
#0 160.8   |   See https://xdebug.org/install.php#configure-php for instructions  |
#0 160.8   |   on how to enable Xdebug for PHP.                                   |
#0 160.8   |                                                                      |
#0 160.9   |   Documentation is available online as well:                         |
#0 160.9   |   - A list of all settings:  https://xdebug.org/docs-settings.php    |
#0 160.9   |   - A list of all functions: https://xdebug.org/docs-functions.php   |
#0 160.9   |   - Profiling instructions:  https://xdebug.org/docs-profiling2.php  |
#0 160.9   |   - Remote debugging:        https://xdebug.org/docs-debugger.php    |
#0 160.9   |                                                                      |
#0 160.9   |                                                                      |
#0 160.9   |   NOTE: Please disregard the message                                 |
#0 160.9   |       You should add "extension=xdebug.so" to php.ini                |
#0 160.9   |   that is emitted by the PECL installer. This does not work for      |
#0 160.9   |   Xdebug.                                                            |
#0 160.9   |                                                                      |
#0 161.0   +----------------------------------------------------------------------+
#0 161.1 shtool:echo:Warning: unable to determine terminal sequence for bold mode
#0 161.2
#0 161.2
#0 161.2 running: find "/tmp/pear/temp/pear-build-defaultuser81DoC2/install-xdebug-3.2.0" | xargs ls -dils
#0 161.2 653189    4 drwxr-xr-x 3 root root    4096 Feb 22 01:30 /tmp/pear/temp/pear-build-defaultuser81DoC2/install-xdebug-3.2.0
#0 161.2 653342    4 drwxr-xr-x 3 root root    4096 Feb 22 01:30 /tmp/pear/temp/pear-build-defaultuser81DoC2/install-xdebug-3.2.0/usr
#0 161.2 653343    4 drwxr-xr-x 3 root root    4096 Feb 22 01:30 /tmp/pear/temp/pear-build-defaultuser81DoC2/install-xdebug-3.2.0/usr/local
#0 161.2 653344    4 drwxr-xr-x 3 root root    4096 Feb 22 01:30 /tmp/pear/temp/pear-build-defaultuser81DoC2/install-xdebug-3.2.0/usr/local/lib
#0 161.2 653345    4 drwxr-xr-x 3 root root    4096 Feb 22 01:30 /tmp/pear/temp/pear-build-defaultuser81DoC2/install-xdebug-3.2.0/usr/local/lib/php
#0 161.2 653346    4 drwxr-xr-x 3 root root    4096 Feb 22 01:30 /tmp/pear/temp/pear-build-defaultuser81DoC2/install-xdebug-3.2.0/usr/local/lib/php/extensions
#0 161.2 653347    4 drwxr-xr-x 2 root root    4096 Feb 22 01:30 /tmp/pear/temp/pear-build-defaultuser81DoC2/install-xdebug-3.2.0/usr/local/lib/php/extensions/no-debug-non-zts-20220829
#0 161.2 653341 2084 -rwxr-xr-x 1 root root 2131208 Feb 22 01:30 /tmp/pear/temp/pear-build-defaultuser81DoC2/install-xdebug-3.2.0/usr/local/lib/php/extensions/no-debug-non-zts-20220829/xdebug.so
#0 161.2
#0 161.2 Build process completed successfully
#0 161.2 Installing '/usr/local/lib/php/extensions/no-debug-non-zts-20220829/xdebug.so'
#0 161.3 install ok: channel://pecl.php.net/xdebug-3.2.0
#0 161.3 cannot open php.ini "/usr/local/etc/php" for writing
#0 161.3 You should add "zend_extension=/usr/local/lib/php/extensions/no-debug-non-zts-20220829/xdebug.so" to php.ini
#0 161.5 /bin/sh: 1: 2enmod: not found
------
Dockerfile:15
--------------------
  14 |     # Patch wegen freetype fehler
  15 | >>> RUN apt-get update \
  16 | >>> && apt-get install -y \
  17 | >>> && pecl install xdebug  \
  18 | >>> && 2enmod rewrite \
  19 | >>> && a2enmod headers
  20 |
--------------------
ERROR: failed to solve: process "/bin/sh -c apt-get update && apt-get install -y && pecl install xdebug  && 2enmod rewrite && a2enmod headers" did not complete successfully: exit code: 127
ERROR: Service 'apache' failed to build : Build failed
grobot@GRobotServer:~/docker $

The Error
cannot open php.ini “/usr/local/etc/php” for writing
is not possible because
i have there 777
ls -la /usr/local/etc/
drwxrwxrwx 3 root root 4096 22. Feb 01:43 php
ls -la /usr/local/etc/php
drwxrwxrwx 2 root root 4096 21. Feb 19:32 conf.d
-rwxrwxrwx 1 grobot grobot 102 22. Feb 02:01 php.ini

After what felt like the twentieth attempt, I had created the php.ini in the directory /usr/local/etc/php and php.ini file myself !!!
I thought it would be better then… but I was wrong

if the error message means
/bin/sh: 1: 2enmod: not found
same same with any freetype error… i installed on my raspberry system this modules already but not interested him

best reagards

achim

edit
there are my group-members

sudo:x:27:pi,grobot
audio:x:29:pi,grobot
dip:x:30:
www-data:x:33:grobot
backup:x:34:
operator:x:37:
list:x:38:
.
.
.
input:x:104:pi,grobot
kvm:x:105:
render:x:106:pi,grobot
crontab:x:107:
netdev:x:108:pi,grobot
.
.
grobot:x:1001:
docker:x:995:grobot,pi

Typo? In the next line you use a2enmod, is this supposed to be the same command?

At least, this is what causes this error:

#0 161.5 /bin/sh: 1: 2enmod: not found

Why would that be relevant when building the image? The volume declaration is only used when running a container, not when building an image. Unless you copy the files into the image using a COPY instruction, the files won’t be present in the image, except of course if the files already exist in the base image.

1 Like

i’m not sure i think rewrite and headers… is that same ?

i use this sample Dockerfile and yaml file from github

but thank’s a lot… i try it and i will tell you the result

Is there an example?
So after creating the image, I first have to create and copy the individual config files

and then I have to specify that in the Dockerfile

Maybe there is a link that documents how to create an image with php and apache

edit:

if i use only a2enmod rewrite
i need then

RUN cp /etc/apache2/mods-available/rewrite.load /etc/apache2/mods-enabled/ 

too ?
i see it there

but they used rewrite and headers too…
but ok… i think mod headers isn’t important for me

edit:
i found
RUN a2enmod rewrite headers

then i have only one command

So you didn’t notice that I quoted your Dockerfile where you used 2enmod instead of a2enmod?

Sure there is a documentation: https://docs.docker.com/engine/reference/builder/#copy

You might want to make it a habit to lookup unclear instructions in the Dockerfile reference.

oh sorry i’m so blind… now i see :frowning:

you told me i have to copy the files…

thats mean… all files what i need … like httpd.conf or php.ini
i have to create first the directory and then the files too
because
i install a apache-image.
Thats run, all was ok, but i not found any config-folder like /etc/apache2

is that normal, i have to configure all?

have i to set the user and group rights too?
i’m now not 100% sure but some years ago if i build self a apache-php, i can not remember i have to copy or create there some default path
If i use a other directory, okay yes then sure i have to copy that
or i missunderstood now

Thanks for the link to the docu

Can’t really tell you how the apache base image is designed. I am not using it. I am not using php at all, so I can’t really recommend on php specifics. I have my roots in java :slight_smile:

Typically you have entrypoint scripts in place that modify configuration files based on environment variables (if the maintainer created it,). So it’s always a good starting point to dig through the image description on dockerhub and see whether they suggest how the image should be extended.

Apache+php8.2+mysql+phpmyadmin
folder structure is
docker
Check this docker-compose.yml + Dockerfile
1- docker-compose.yml

version: "3.9"

services:

  apache:
    image: httpd:latest
    container_name: apacheserver
    restart: always
    ports:
      - "80:80"
      - "443:443"
    volumes:
      - ./web/:/var/www/html
      - ./apache/conf/httpd.conf:/usr/local/apache2/conf/httpd.conf
    networks:
      - webappnet
    command: apachectl -DFOREGROUND
    links:
      - php:php
      - mysql:mysql
    depends_on:
      - php
      - mysql

  php:
    container_name: phpserver
    build:
      context: .
      dockerfile: Dockerfile
    restart: always
    volumes:
      - ./web/:/var/www/html
      - ./env/phpcustom:/usr/local/etc/conf.d/custom.ini
    networks:
      - webappnet
    links:
      - mysql:mysql
    depends_on:
      - mysql

  mysql:
    container_name: mysqlserver
    image: mysql:8.0
    restart: always
    environment:
      MYSQL_ROOT_PASSWORD: root
    ports:
      - "3306:3306"
    volumes:
      - ./db/mysql-data:/var/lib/mysql
      - ./db/mysqlcustom:/etc/mysql/conf.d/my.cnf
    networks:
      - webappnet

  phpmyadmin:
    container_name: pmaserver
    image: phpmyadmin:latest
    restart: always
    ports:
      - "8080:80"
    environment:
      PMA_HOST: mysqlserver
      PMA_PORT: 3306
      PMA_ARBITRARY: 1
    networks:
      - webappnet
    volumes:
      - ./db/phpmyadmin:/var/lib/phpmyadmin
    depends_on:
    - mysql

networks:
  webappnet:

2- Dockerfile

FROM php:8.2-apache

# mod_rewrite
RUN a2enmod rewrite

# Install necessary build tools
RUN apt-get update && apt-get install -y \
    gcc \
    make \
    autoconf \
    && rm -rf /var/lib/apt/lists/*

# Install required extensions and dependencies
RUN apt-get update && apt-get install -y \
    libbz2-dev \
    libcurl4-openssl-dev \
    libxml2-dev \
    mariadb-client \
    libssl-dev \
    libldap-dev \
    libpcre3-dev \
    libmariadb-dev \
    libonig-dev \
    libpng-dev \
    libjpeg-dev \
    libzip-dev \
    zip \
    unzip \
    libicu-dev \
    libldap2-dev \
    libgd-dev \
    libpq-dev
 # Remove default PHP extensions
RUN docker-php-ext-install -j$(nproc) \
    mysqli \
	pdo_mysql \
    ctype \
    soap \
    session \
    dom 
 # Install additional PHP extensions
RUN docker-php-ext-install -j$(nproc) \
    bcmath \
    zip \
    intl \
    gd \
    bz2 \
    mbstring \
    pgsql \
    opcache
 # Enable LDAP extension
RUN docker-php-ext-configure ldap --with-libdir=lib/x86_64-linux-gnu/ \
    && docker-php-ext-install ldap

# Disable exposing server information
RUN sed -ri -e 's!expose_php = On!expose_php = Off!g' $PHP_INI_DIR/php.ini-production
RUN sed -ri -e 's!ServerTokens OS!ServerTokens Prod!g' /etc/apache2/conf-available/security.conf
RUN sed -ri -e 's!ServerSignature On!ServerSignature Off!g' /etc/apache2/conf-available/security.conf
RUN mv "$PHP_INI_DIR/php.ini-production" "$PHP_INI_DIR/php.ini"

# Set the Apache document root
ENV APACHE_DOCUMENT_ROOT=/var/www/html/

# Enable Apache modules
RUN a2enmod rewrite setenvif
RUN a2dissite *
RUN a2disconf other-vhosts-access-log

COPY ./apache/conf/httpd.conf /usr/local/apache2/conf/httpd.conf

# Add index.php to the default document root
COPY ./web/* /var/www/html/

# Expose ports
EXPOSE 80
EXPOSE 443

# Start Apache in the foreground
CMD ["apache2ctl", "-D", "FOREGROUND"]



Thank you :wink: