Docker Container Apache / httpd:2.4 .htcaccess file does not work

I have a problem. I have the problem that my .htaccess file does not work. I run it locally via XAMPP and start Apache from there, everything works fine.

How can I make it so that the .htaccess also runs via Docker?

Commands

# sudo docker run -dit --name mywebsite-p 8080:80 -v /home/user/website/:/usr/local/apache2/htdocs/ httpd:2.4

You need a customized configuration file where you can enable AllowOverride. This is the relevant section from /usr/local/apache2/conf/htdocs.conf

<Directory "/usr/local/apache2/htdocs">
    #
    # Possible values for the Options directive are "None", "All",
    # or any combination of:
    #   Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews
    #
    # Note that "MultiViews" must be named *explicitly* --- "Options All"
    # doesn't give it to you.
    #
    # The Options directive is both complicated and important.  Please see
    # http://httpd.apache.org/docs/2.4/mod/core.html#options
    # for more information.
    #
    Options Indexes FollowSymLinks

    #
    # AllowOverride controls what directives may be placed in .htaccess files.
    # It can be "All", "None", or any combination of the keywords:
    #   AllowOverride FileInfo AuthConfig Limit
    #
    AllowOverride None

    #
    # Controls who can get stuff from this server.
    #
    Require all granted
</Directory>

The easiest way to make htaccess work is changing AllowOverride None to AllowOverride All. You can set a more restricted value but this enables everything to override in an htacces file.

Copy out the current config:

docker run --rm -it httpd:2.4 cat /usr/local/apache2/conf/httpd.conf > httpd.conf

and change the config and create a new image with the new config, or just mount the config file

docker run -v $PWD/httpd.conf:/usr/local/apache2/conf/httpd.conf ...

Thank you very much for your help!

and change the config and create a new image with the new config, or just mount the config file
docker run -v $PWD/httpd.conf:/usr/local/apache2/conf/httpd.conf ...

How exactly do I do that? I copied the code before and executed it, but the second one gives me an error and I don’t know exactly how to do it. Could you please help me?

If you have “an error”, you need to fix it :slight_smile: Unless you give us more information about that error I can’t help you. You should also share how you tried to run commands we suggested. Without that there is no other way than guessing.

Do what? I suggested two solutions and I also gave you an example for one of them.