To activate the new configuration, you need to run: service apache2 restart

Hello,
My YAML file is as follows:

version: "3.9"
services:
  webserver:
    image: php:8.2-apache
    container_name: Apache_PHP
    volumes:
      - /var/www/html:/usr/local/apache2/htdocs/
    ports:
      - 8000:80
    depends_on:
      - mysql-db
    command: a2enmod rewrite && apt update && apt install docker-php-ext-install mysqli pdo pdo_mysql

  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

I created the containers:

# docker compose up -d
[+] Restarting 3/3
 ✔ Container MySQL                 Started                                                                                                 3.3s 
 ✔ Container Apache_PHP            Started                                                                                                 0.9s 
 ✔ Container phpMyAdmin            Started         
 

But Apache is not running:

# docker compose ps
NAME                   IMAGE               COMMAND                  SERVICE      CREATED         STATUS          PORTS
MySQL                  mysql:latest        "docker-entrypoint.s…"   mysql-db     8 minutes ago   Up 23 seconds   0.0.0.0:3306->3306/tcp, :::3306->3306/tcp, 33060/tcp
phpMyAdmin             phpmyadmin:latest   "/docker-entrypoint.…"   phpmyadmin   8 minutes ago   Up 19 seconds   0.0.0.0:8081->80/tcp, :::8081->80/tcp

I checked the log and saw the following message:

# docker compose logs
...
Apache_PHP    | Enabling module rewrite.
Apache_PHP    | To activate the new configuration, you need to run:
Apache_PHP    |   service apache2 restart
Apache_PHP    | Module rewrite already enabled

What should I do?

Cheers.

Hello

I think you use the option command in the Docker compose file to CMD or Entrypoint in the apache image, so I think you need to add a command to run again.

I understand your situation. Originally, it should be executed, of course, but since you added a new module installation command, you need to enter the apache execution command.

Best Regards,
limsangwoon

1 Like

Hi,
Thank you so much for your reply.
How to enter the apache execution command? What command should I add?

Hello,
if you look at the inspct of the image you’re currently using
It seems that we are proceeding with the execution as below.
image

Add that execution command to the command line in the same way.

Hello,
Thank you so much for your reply.
Do you mean something like the line below?

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

If this is the case, then I got the same result as above.

Hello

dockerfile

FROM php:8.2-apache
RUN a2enmod rewrite \
&& && apt update \
&& && apt install -y \
&& && docker-php-ext-install mysqli pdo pdo_mysql

compose file

services:
  webserver:
    build: .
    container_name: Apache_PHP
    volumes:
      - /var/www/html:/usr/local/apache2/htdocs/
    ports:
      - 8000:80
    depends_on:
      - mysql-db

Then why don’t you make an apache docker file separately as above and run it in compose?
Please modify the components file as above and place the docker file in the same location.

Hi,
Thanks again.
I want to do this using the command command, not the Dockerfile. Is the command not able to do this? So what is the use of this command?