How to Solve Error Message AH01276: Cannot serve directory /: No matching DirectoryIndex (index.html,index.php) found, and server-generated directory index forbidden by Options directive

Posted on

This article will discuss about how to solve an error message as exist in the title of this article itself. Basically, the context of this article is troubleshooting to solve why a web-based application using Yii framework is not working. The actual error message exist as follows :

AH01276: Cannot serve directory /folder-path-root-web-location/: No matching DirectoryIndex (index.html,index.php) found, and server-generated directory index forbidden by Options directive

The error above exist after searching the cause in the error log file of Apache Webserver. It is because in the default root folder of the web-based application using Yii framework there is no file with the name of ‘index.html’ or ‘index.php’. Actually, there is a reason for Apache Webserver looking for the ‘index.html’ or ‘index.php’ file for initial execution of the web-based application. The reason is available in the Apache Webserver’s virtual host web-based application configuration. The configuration itself can exist in the main Apache Webserver’s file configuration. But it can also exist in other file configuration focusing on the virtual host definition. The following is the configuration lines for virtual host definition in order to inform Apache Webserver about how to access the web-based application :

<VirtualHost *:80>
ServerName localhost.webapps.web
ServerAdmin webmaster@localhost.webapps.web
DocumentRoot /var/www/html/webapps
    <Directory /var/www/html/webapps> 
             DirectoryIndex index.html index.php 
             Options -Indexes +FollowSymLinks +MultiViews AllowOverride All Require all granted 
    </Directory> 
ErrorLog /var/www/html/webapps/logs/localhost.webapps.web-error.log 
CustomLog /var/www/html/webapps/logs/localhost.webapps.web-access.log combined 
</VirtualHost>

As it is exist from the above line of configuration, there is a line as follows :

DirectoryIndex index.html index.php

The above line configuration means that index.html and index.php will be an index file in the root directory of the web-based application. So, the solution is simple. Just point of the root directory folder of the web-based application which contains the index.html or the index.php file. In the context of web-based application using Yii framework, it exist in the ‘web’ folder. So, change the DocumentRoot entry into the following line :

DocumentRoot /var/www/html/webapps/web

Make sure there is a file with the name of ‘index.html’ or ‘index.php’. Just check inside of the folder. Finally, don’t forget to restart the Apache Webserver’s service.

Leave a Reply