dockerdrupal

Problem with Docker Setup: Drupal Container Shows "403 Forbidden" Error


I have set up a Docker environment for Drupal that consists of three services: Drupal, MySQL, and phpMyAdmin. When I try to access Drupal on port 8085, I encounter a "403 Forbidden Error. Below is my docker-compose.yml configuration:

services:
  drupal:
    image: drupal:9
    container_name: drupal
    ports:
      - "8085:80"
    volumes:
      - ./drupal:/var/www/html
    depends_on:
      - db
    networks:
      - drupal-network
  db:
    image: mysql:5.7
    container_name: drupal-db
    environment:
      MYSQL_ROOT_PASSWORD: root
      MYSQL_DATABASE: drupal
      MYSQL_USER: drupal
      MYSQL_PASSWORD: drupal
    volumes:
      - db-data:/var/lib/mysql
    networks:
      - drupal-network
  phpmyadmin:
    image: phpmyadmin/phpmyadmin
    container_name: phpmyadmin-drupal
    ports:
      - "8081:80"
    environment:
      PMA_HOST: db
      MYSQL_ROOT_PASSWORD: root
    depends_on:
      - db
    networks:
      - drupal-network
volumes:
  db-data:
networks:
  drupal-network:
    driver: bridge

Problem Description:

When I try to access Drupal on http://localhost:8085, I get a "403 Forbidden" error.
The drupal container starts successfully, and I can see the logs, but Drupal doesn’t load.
phpMyAdmin works fine on port 8081.

Things I have tried: Restarting all the containers with docker-compose restart. Verifying that MySQL credentials are correct and Drupal is properly configured to connect to the database.

Can anyone suggest why I might be getting the "403 Forbidden" error and how to resolve it?


Solution

  • I'm not a web developer but error is rather clear:

    drupal             | [Sun Nov 17 16:42:43.247661 2024] [autoindex:error] [pid 17] [client 172.21.0.1:48032] AH01276: Cannot serve directory /var/www/html/: No matching DirectoryIndex (index.php,index.html) found, and server-generated directory index forbidden by Options directive
    

    You either need to put some basic index.html in ./drupal or remove this:

    volumes:
      - ./drupal:/var/www/html
    

    from docker-compose.yml to use the default installer:

    $ docker exec -it drupal bash
    root@c590effc0365:/opt/drupal# ls -l /var/www/html
    lrwxrwxrwx 1 root root 15 Dec  1  2023 /var/www/html -> /opt/drupal/web
    root@c590effc0365:/opt/drupal# ls -Alh web
    total 76K
    -rw-r--r--  1 root     root     1.1K Dec  1  2023 .csslintrc
    -rw-r--r--  1 root     root      151 Dec  1  2023 .eslintignore
    -rw-r--r--  1 root     root       41 Dec  1  2023 .eslintrc.json
    -rw-r--r--  1 root     root     2.5K Dec  1  2023 .ht.router.php
    -rw-r--r--  1 root     root     7.6K Dec  1  2023 .htaccess
    -rw-r--r--  1 root     root       94 Dec  1  2023 INSTALL.txt
    -rw-r--r--  1 root     root     3.2K Dec  1  2023 README.md
    -rw-r--r--  1 root     root      315 Dec  1  2023 autoload.php
    drwxr-xr-x 12 root     root     4.0K Dec  1  2023 core
    -rw-r--r--  1 root     root     1.5K Dec  1  2023 example.gitignore
    -rw-r--r--  1 root     root      549 Dec  1  2023 index.php
    drwxr-xr-x  2 www-data www-data 4.0K Dec  1  2023 modules
    drwxr-xr-x  2 root     root     4.0K Dec  1  2023 profiles
    -rw-r--r--  1 root     root     1.7K Dec  1  2023 robots.txt
    drwxr-xr-x  3 www-data www-data 4.0K Dec  1  2023 sites
    drwxr-xr-x  2 www-data www-data 4.0K Dec  1  2023 themes
    -rw-r--r--  1 root     root      804 Dec  1  2023 update.php
    -rw-r--r--  1 root     root     4.0K Dec  1  2023 web.config