Fix: index.php not being loaded by default.

The is a short guide on how to solve the issue of index.php files not being served as the default file (aka the DirectoryIndex). Example: You browse to your website and the web server lists the files and folders in your public web root or you are met with a nasty 403 forbidden error.


To fix the issue with Apache web server, you will need to tell it that “index.php” files should be treated the same as “index.html” files. A quick fix is to create a .htaccess file with the following line:

However, using .htaccess files should be avoided if you happen to have access to Apache’s configuration files. A better approach is to modify the httpd.conf file and add the following:

In the config snippet above, we tell Apache that index.php is the DirectoryIndex. We also specify that index.html should be used as the DirectoryIndex if a index.php file is not present inside the current directory.


If you are using PHP-FPM with nginx as the web server, then you will need to make sure that your sites-available configuration file has something similar to the following:

You only need to pay attention to the second line, as the rest of the configuration settings may be slightly different than what you are currently using. In the configuration snippet above, we have told our nginx web server that the index is “index.php”, “index.html” or “index.htm” – in that order of preference. If nginx is not serving your index.php file as the default directory index file, then it is possible that your settings look something like this:

Notice what is missing?

NOTE: If you are making changes to Apache or nginx, please make sure that you have restarted your web server or that you have reloaded your configuration values. Otherwise, the changes will not take place with immediate effect.