sprintcube / docker-compose-lamp

A basic LAMP stack environment built using Docker Compose.
MIT License
2.68k stars 1.42k forks source link

[BUG] APACHE_DOCUMENT_ROOT isn't respected #212

Closed struffel closed 1 year ago

struffel commented 2 years ago

Describe the bug The environment variable APACHE_DOCUMENT_ROOT is ignored, instead the default /var/www/html value is used.

which Branch / PHP Version are you using ? php81

Steps to reproduce Steps to reproduce the behavior: Set up the .env file with these settings:

DOCUMENT_ROOT=D:/Git/my-repo/src
APACHE_DOCUMENT_ROOT=/var/www/html/public

(The entire src-folder should be mounted to the container but only the path /src/public should be used as the root so that other code is outside the document root.)

When using this setup and performing docker compose up the document root for the apache server is still set to /var/www/html. This can be verified by launching a shell inside the php81 container (docker exec) and printing the configuration file: cat /etc/apache2/sites-available/000-default.conf The important line still reads DocumentRoot /var/www/html and this is also the setting that the apache server actually uses.

Expected behavior The config file should contain /var/www/html/public as the document root, as specified in the .env file and the server should use the public folder as the document root.

Screenshots image

Desktop (please complete the following information): Windows 10 Home with Docker Desktop 4.10.1 using Docker Engine v20.10.17.

docker -v
Docker version 20.10.17, build 100c701

Additional context Here is the entire .env file:

# Please Note:
# In PHP Versions <= 7.4 MySQL8 is not supported due to lacking pdo support

# To determine the name of your containers
COMPOSE_PROJECT_NAME=lamp

# Possible values: php54, php56, php71, php72, php73, php74, php8, php81
PHPVERSION=php81
DOCUMENT_ROOT=D:/Git/my-repo/src
APACHE_DOCUMENT_ROOT=/var/www/html/public
VHOSTS_DIR=./config/vhosts
APACHE_LOG_DIR=./logs/apache2
PHP_INI=./config/php/php.ini
SSL_DIR=./config/ssl

# PHPMyAdmin
UPLOAD_LIMIT=512M
MEMORY_LIMIT=512M

# Xdebug
XDEBUG_LOG_DIR=./logs/xdebug
XDEBUG_PORT=9003
#XDEBUG_PORT=9000

# Possible values: mysql57, mysql8, mariadb103, mariadb104, mariadb105, mariadb106
#
# For Apple Silicon User: 
# Please select Mariadb as Database. Oracle doesn't build their SQL Containers for the arm Architecure

DATABASE=mysql57
MYSQL_INITDB_DIR=./config/initdb
MYSQL_DATA_DIR=./data/mysql
MYSQL_LOG_DIR=./logs/mysql

# If you already have the port 80 in use, you can change it (for example if you have Apache)
HOST_MACHINE_UNSECURE_HOST_PORT=80

# If you already have the port 443 in use, you can change it (for example if you have Apache)
HOST_MACHINE_SECURE_HOST_PORT=443

# If you already have the port 3306 in use, you can change it (for example if you have MySQL)
HOST_MACHINE_MYSQL_PORT=3306

# If you already have the port 8080 in use, you can change it (for example if you have PMA)
HOST_MACHINE_PMA_PORT=8080
HOST_MACHINE_PMA_SECURE_PORT=8443

# If you already has the port 6379 in use, you can change it (for example if you have Redis)
HOST_MACHINE_REDIS_PORT=6379

# MySQL root user password
MYSQL_ROOT_PASSWORD=xxx

# Database settings: Username, password and database name
#
# If you need to give the docker user access to more databases than the "docker" db 
# you can grant the privileges with phpmyadmin to the user.
MYSQL_USER=xxx
MYSQL_PASSWORD=xxx
MYSQL_DATABASE=xxx
MrOffline77 commented 2 years ago

Hi, ehm so If I am not completely wrong ... you understand it not correct. The document root var is used for a volume mount. This volume will be mapped from your pc to the default docroot inside the container. The Container expects the docroot under /var/www/html so therfore from the inside view of the container its totally okay when this is stays unchanged. The only thing you can control with the docroot var from the env file is the Volume you want to map into the container under /var/www/html. So the string inside the apacheconfig will never change when you change the docroot var in the env.

from docker-compose.yml

    volumes:
      - ${DOCUMENT_ROOT-./www}:/var/www/html:rw

Let me know if that explanation was useful to you :)