Search code examples
apachedockermod-rewritebuild

How to enable mod_rewrite module for docker official httpd image?


I am running a LAMP stack in docker with the help from docker-compose, and for the webserver I am using the official image from https://hub.docker.com/_/httpd. The httpd container is created by a Dockerfile:

ARG APACHE_VERSION
FROM httpd:$APACHE_VERSION
RUN apt-get update;\apt-get upgrade;\a2enmod rewrite
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

I am trying to enable mod_rewrite with the \a2enmod rewrite command but I get the following error during build:

/bin/sh: 1: a2enmod: not found
ERROR: Service 'apache' failed to build: The command '/bin/sh -c apt-get update;\apt-get upgrade;\a2enmod rewrite' returned a non-zero code: 127

a2enmod is failing – from my reading it's only available in a debian system and the httpd base image doesn't have it.

How can I enable mod_rewrite module for this docker official httpd image during build?


Solution

  • I ended up figuring it out. I had to enable the module in the apache .conf file by adding the line:

    LoadModule rewrite_module modules/mod_rewrite.so