Apache container .htaccess

Hello,

i am trying to set 3 containers with docker-compose: 1.php /2.apache/3.mysql. All works fine at the time i load a simple .php file.
But i want to load the project with a .htaccess, then it doesn’t work anymore and give me an err-server.

here is the docker-compose.yml

   version: "3.2"
services:
    php:
        build: './php/'
        volumes:
            - ./MediterPourGrandir/Web/:/var/www/html/
    apache:
        build: './apache/'
        depends_on:
            - php
        ports:
            - "80:80"
        volumes:
            - ./MediterPourGrandir/Web/:/var/www/html/
    mysql:
        image: mysql:5.6.40
        environment:
            - MYSQL_ROOT_PASSWORD=rootpassword

Here is the php docker file`

    FROM php:7.2.7-fpm-alpine3.7
    RUN apk update; \
        apk upgrade;

    RUN docker-php-ext-install mysqli

Here is the apache docker file, as you can see i did try to allow the rewriting mode, but docker show an err (/bin/sh: a2enmod: not found
ERROR: Service ‘apache’ failed to build: The command ‘/bin/sh -c a2enmod rewrite’ returned a non-zero code: 127)

    FROM httpd:2.4.33-alpine
RUN apk update; \
    apk upgrade; 

# here docker do not load, and show the err 
# RUN a2enmod rewrite

# here docker load but the page display an err-server
# Enable mod_rewrite for images with apache
# RUN if command -v a2enmod >/dev/null 2>&1; then \
#        a2enmod rewrite headers \
#    ;fi


# Copy apache vhost file to proxy php requests to php-fpm container
COPY demo.apache.conf /usr/local/apache2/conf/demo.apache.conf

RUN echo "Include /usr/local/apache2/conf/demo.apache.conf" \
    >> /usr/local/apache2/conf/httpd.conf

There is the demo.apache.conf

ServerName localhost

LoadModule deflate_module /usr/local/apache2/modules/mod_deflate.so
LoadModule proxy_module /usr/local/apache2/modules/mod_proxy.so
LoadModule proxy_fcgi_module /usr/local/apache2/modules/mod_proxy_fcgi.so

<VirtualHost *:80>
   ProxyPassMatch ^/(.*\mediterpourgrandir(/.*)?)$ fcgi://php:9000/var/www/html/$1
   DocumentRoot /var/www/html/
 # if i run this file 'with no .htaccess in the same folder' it's working
 # DirectoryIndex index.php
   Options Indexes FollowSymLinks MultiViews

   <Directory /var/www/html/>
     # DirectoryIndex index.php
     Options All
     AllowOverride All
     Require all granted
   </Directory>
 </VirtualHost>

I did google for few days, but i didn’t find the solution… If someone have an idea, it would be nice, thank you.

ps. i am kind of new born with docker, so forgive me in case of stupid mistakes…

See this article for good advice:

yes, thank you. It s actually the same setup i have, i did it following a web tutorial (not this one, but the codes are exactly same). Like they explain it’s working well, but they root their application with an index.php and i root mine with an .htaccess. My problem is here.

From my original post i moved on, i did allow the rewriting of apache (that was missing in the apache Dockerfile),

RUN sed -i '/LoadModule rewrite_module/s/^#//g' /usr/local/apache2/conf/httpd.conf && \
    sed -i 's#AllowOverride [Nn]one#AllowOverride All#' /usr/local/apache2/conf/httpd.conf

the volumes, ports and builds are good, the server run (no err 500 anymore), but the .htaccess is still not loading…

1 Like