Remove Dockerfile

Hello,
To install and configure Apache, PHP, MySQL and PhpMyAdmin, I read the article https://thriveread.com/apache-php-with-docker-mysql-and-phpmyadmin/. I have some questions:

1- This article uses the php:8.2-apache package, but I want to install Apache and PHP separately. I changed the configuration file as follows:

version: "3.9"
services:
  webserver:
    image:httpd:latest
    container_name: Apache
    volumes:
      - /var/www/html:/usr/local/apache2/htdocs/
      - ./httpd.conf:/usr/local/apache2/conf/httpd.conf
    ports:
      - 8000:80
    depends_on:
      - mysql-db
      - php-fpm

  php-fpm:
    image: php:8-fpm
    container_name: PHP
    volumes:
       - /var/www/html:/usr/local/apache2/htdocs/

  mysql-db:
    image: mysql:latest
    container_name: MySQL
    environment:
      MYSQL_ROOT_PASSWORD: password
      MYSQL_DATABASE: test_database
      MYSQL_USER: db_user
      MYSQL_PASSWORD: password
    ports:
      - "3306:3306"

  phpmyadmin:
    image: phpmyadmin:latest
    container_name: PhpMyAdmin
    links:
      - mysql-db
    ports:
      - "8081:80"
    environment:
      PMA_HOST: mysql-db
      MYSQL_ROOT_PASSWORD: password

Is this configuration file correct?

2- The article uses Dockerfile and I don’t want that. How can I install the following extensions without needing a Dockerfile?

docker-php-ext-install mysqli pdo pdo_mysql

3- Why is PhpMyAdmin only linked to MySQL and not PHP?

Cheers.

1 Like

Hello, hack3rcon

It seems that you are interested in installing and configuring Apache, PHP, MySQL, and phpMyAdmin using Docker. We will answer your questions.

  1. Is this configuration file correct?
  • Yes, the docker compose file you provided is configured correctly.
  1. The article uses Dockerfile and I don’t want that. How can I install the following extensions without
    needing a Dockerfile ?
  • If you prefer to install extensions without using Dockerfile, it is limited except to directly use an image that
    contains PHP extensions or create a custom image.
    If additional extensions are needed, a common approach is to build a custom image using Dockerfile. It is
    difficult to dynamically add extensions without Dockerfile.
  1. Why is PhpMyAdmin only linked to MySQL and not PHP?
  • phpMyAdmin is a web-based MySQL database management tool that connects directly to the MySQL server.
    It does not connect to PHP itself, but interacts with MySQL by performing database operations through PHP
    code.

Thanks and cheers!
Subin Lee.

1 Like

Hello,
Thank you so much for your reply.
1- The Dockerfile of the article is as follows:

# Use an official PHP runtime
FROM php:8.2-apache
# Enable Apache modules
RUN a2enmod rewrite
# Install any extensions you need
RUN docker-php-ext-install mysqli pdo pdo_mysql
# Set the working directory to /var/www/html
WORKDIR /var/www/html
# Copy the source code in /www into the container at /var/www/html
COPY ../www .

I use httpd:latest image and added the following command in the YAML file:

command: a2enmod rewrite && apt update && apt install docker-php-ext-install mysqli pdo pdo_mysql

But I got the following error:

Error response from daemon: failed to create task for container: failed to create shim task: OCI runtime create failed: runc create failed: unable to start container process: exec: "a2enmod": executable file not found in $PATH: unknown

It seems that this problem is related to the image that I am using. How can I find out which commands an image supports?

2- About PhpMyAdmin, my question was that this management tool uses the PHP programming language, so it must be linked to PHP. Isn’t it?