skip to Main Content
version: "3.8"

networks:
  frontend:
  backend:
services:
  apache:
    container_name: apache
    build: ./docker/apache/
    ports:
      - "8001:80"
    volumes:
      - ./src:/usr/local/apache2/htdocs
    networks:
      - frontend
      - backend
  php:
    container_name: php
    build: ./docker/php
    ports:
      - "9001:9000"
    volumes:
      - ./src:/usr/local/apache2/htdocs
    working_dir: /usr/local/apache2/htdocs
    networks:
      - backend

apache.conf

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 ^/(.*.php(/.*)?)$ fcgi://php:9000/usr/local/apache2/htdocs/$1

    DocumentRoot /usr/local/apache2/htdocs

    <Directory /usr/local/apache2/htdocs/public>
        Options -Indexes +FollowSymLinks
        DirectoryIndex index.php
        AllowOverride All
        Require all granted
    </Directory>
</VirtualHost>

enter image description here
As you can see Project folder Directory. when try to access http://localhost:8002/ it’s not show public folder in browser index of.

enter image description here

When Change the Directory path in apache.conf File not found. error message is showing on browser

<Directory /usr/local/apache2/htdocs/public>

PHP Dockerfile

FROM php:8.1-fpm

COPY php.ini /usr/local/etc/php/conf.d/php.ini

RUN apt-get update 
  && apt-get install -y libfreetype6-dev libjpeg62-turbo-dev libpng-dev libmcrypt-dev 
  && docker-php-ext-install pdo 

Apache Dockerfile

FROM httpd:2.4.51
COPY apache.conf /usr/local/apache2/conf/apache.conf

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

2

Answers


  1. For testing, try instead the --mount syntax, with a full path as source, on docker run:

     --mount type=bind,source=/path/to/src,target=/usr/local/apache2/htdocs
                              ^^^^^^^^^^^^
    

    It specifies a bind mount, which means a file or directory on the host machine is mounted into a container.


    Check also the output of docker inspect yourContainer, in order to see what volume has been set up.

    Login or Signup to reply.
  2. Since all your other files are showing up it’s most likely a permissions issue. Your public directory is probably owned by the apache or http or www-data user on your host system and that user’s uid and/or gid do not match what is being used inside the container. You can find out the ids of the host user like this…

    First, determine the right username :

    ls -l ./src/public
    

    Then get the uid of that user :

    id -u www-data
    

    And the gid :

    id -g www-data
    

    Finally, append the below lines to your apache Dockerfile, replacing the ARG values with the results of the above commands :

    ARG UID=33
    ARG GID=33
    RUN usermod -u ${UID} www-data 
    && usermod -g ${GID} www-data 
    && chown -hR www-data:www-data /usr/local/apache2
    

    The official httpd image that you are using runs as the user www-data so do not change that in the usermod commands, we are just changing the ids of the existing user in the container to match your host system.

    To make this more flexible/portable you can also pass the values in from your compose file.

    Alternatively

    For a quick and dirty fix, just do chmod -R a+r ./src/public on the host. This will probably work but is less secure. However, if you are just testing things out or only setting up this project for personal use then this may be the easiest solution.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search