How to change the document root in PHP:7.1-apache from docker-compose.yml
I found a solution for this issue. basically, it worked when I created a Dockerfile with build commands. So the following structure fixed the issue:
docker-compose.yml
version: '3'
services:
web:
build: .
ports:
- 80:80
volumes:
- ./src:/var/www/html
Dockerfile
FROM php:7.1-apache
ENV APACHE_DOCUMENT_ROOT=/var/www/html/public
RUN sed -ri -e 's!/var/www/html!${APACHE_DOCUMENT_ROOT}!g' /etc/apache2/sites-available/*.conf
RUN sed -ri -e 's!/var/www/!${APACHE_DOCUMENT_ROOT}!g' /etc/apache2/apache2.conf /etc/apache2/conf-available/*.conf
Just remember to run docker-compose build before running the image (if anybody else have the same problem).
For testing temporary solutions, you can manually change the apache .conf file. When your container is running, enter the bash:
docker exec -it your_container_name bash
Edit the content of the .conf file:
vim /etc/apache2/sites-available/000-default.conf
(if vim is not found, run apt-get update
and apt-get install vim
)
Finally reload apache:
/etc/init.d/apache2 reload