AH01276: Cannot serve directory /var/www/html/: No matching DirectoryIndex (index.php,index.html) found

AH01276: Cannot serve directory /var/www/html/: No matching DirectoryIndex (index.php,index.html) found

  1. Blog
  2. 15 November 2026
  3. 4 min read

Stefan Bogdanescu

Founder & Senior Architect

AH01276: Cannot serve directory /var/www/html/: No matching DirectoryIndex found

The error message AH01276: Cannot serve directory /var/www/html/: No matching DirectoryIndex (index.php,index.html) found is a classic Apache configuration failure that often trips up developers setting up PHP containers with Docker. The log explicitly states two things: the server cannot find a default index file in /var/www/html/, and it refuses to generate an auto-index listing because the Options directive forbids it.

In your specific setup, the root cause is a mismatch between Apache's built-in default configuration and your custom virtual host settings. When you use the official php:7.1-apache image, Apache initializes with a default site configuration defined in /etc/apache2/sites-available/000-default.conf. This file points the DocumentRoot to /var/www/html.

Even though you have created a custom project.conf (or renamed it to site-default.conf in your local config), Apache's startup sequence depends heavily on what modules are enabled and which sites are loaded at boot time. If your custom configuration files are not being picked up correctly, or if the default 000-default.conf is still active and taking precedence, Apache will serve requests against /var/www/html.

The error occurs because that directory likely does not exist or is empty within the container image. The official PHP Apache images do not include a pre-populated /var/www/html directory with an index.php file. Consequently, when you hit the root URL, Apache looks for index.php or index.html in /var/www/html, fails to find them, and then checks if Indexes is allowed. Since your default configuration usually sets Options -Indexes (forbidden by default in many LAMP stacks unless explicitly overridden), Apache returns this specific error instead of generating a directory listing.

Fixing the DocumentRoot Mismatch

The most reliable way to resolve this is to ensure that your custom virtual host configuration is actually being loaded and that it correctly defines the DocumentRoot.

First, verify that your custom site configuration file exists in the correct location within the container. In your Dockerfile, you are copying site-default.conf to /etc/apache2/sites-available/000-default.conf. This filename suggests it should replace the default 000-default config, but you must ensure the content inside matches your intent.

Your site-default.conf snippet shows:

<VirtualHost *:5001>
  DocumentRoot /usr/src/fileserver/public

This is correct for your volume mount strategy where your code sits in /usr/src/fileserver. However, Apache needs to know which site file to load. Ensure that a2ensite is run for your custom config or that the filename aligns with what a2dissite removes if you are disabling the default.

In your Dockerfile, you have:

RUN a2enmod rewrite
RUN a2enmod headers
# Missing: Explicitly enabling or disabling specific sites

You should explicitly enable your custom site and disable the default one to prevent conflicts. Add these lines to your Dockerfile after copying the config files:

RUN a2ensite project.conf
RUN a2dissite 000-default.conf

Alternatively, if you prefer to keep the filename as 000-default.conf, ensure the DocumentRoot inside that file is set to /usr/src/fileserver/public and that the directory exists. You can create the directory in your Dockerfile or via a mount:

RUN mkdir -p /usr/src/fileserver/public

Verifying the Volume Mount

Your docker-compose.yml mounts your local ./FileServer/ directory to /usr/src/fileserver. If your application files are placed inside a subdirectory (e.g., ./FileServer/myapp), Apache might still be looking at the root of the mounted volume if the DocumentRoot is misconfigured.

Ensure that your web entry point points exactly where your index.php resides. If your project structure places public/index.php inside /usr/src/fileserver, then your DocumentRoot /usr/src/fileserver/public directive is correct. Just make sure that directory exists and contains an index.php.

If you are using Laravel or a similar framework, remember that the public folder is usually separate from the root project directory. If you mount the entire project root to /usr/src/fileserver, ensure your DocumentRoot points to the specific public subdirectory, not the top level.

Final Configuration Check

Once you have updated your Dockerfile to explicitly enable your custom site and disable the default, rebuild the image:

docker-compose build --no-cache
docker-compose up -d

Check the Apache error logs again inside the container:

docker exec fileServer tail -f /var/log/apache2/error.log

You should see requests being served from the correct DocumentRoot without the AH01276 error. If you are still facing issues, double-check that your custom config file syntax is valid by running apachectl configtest inside the container before starting it.

Our network