Fix: index.php not being loaded by default.

In certain cases, your web server might fail to serve “index.php” as the default file.

For example, you might notice that your web server is listing all of the files and folders in your public web root.

Or perhaps you are seeing a nasty 403 forbidden error.


If you are using Apache, then you will need to tell it to treat “index.php” files the same as “index.html” files.

As a “quick fix”, you can create a .htaccess file with the following line:

#The DirectoryIndex is index.php
DirectoryIndex index.php index.html

You can then place the file above in the public directory of your web server.

However, using .htaccess files isn’t always the best approach.

If you have access to Apache’s configuration files, then you should modify the httpd.conf file and add the following:

<IfModule dir_module>
    DirectoryIndex index.php
    DirectoryIndex index.html

In the config above, we tell Apache that “index.php” is the DirectoryIndex. We also specify that it should use “index.html” as the DirectoryIndex if an “index.php” file is not present.

Basically, the html file is our fallback.

Nginx not showing index.php.

If you are using PHP-FPM and Nginx, then you will need to change the “index” directive in your sites-available configuration file.

For example, you might use the following:

location / {
    index index.php index.html index.htm;
    try_files $uri $uri/ =404;

Please note that the configuration settings above might be slightly different than what you are currently using.

In the snippet above, we have told our Nginx web server that the index is “index.php”, “index.html” or “index.htm” – in that order.

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:

index index.html index.htm;

As you can see, the “.php” file is missing from the line above.

If you are making changes to Apache or Nginx, please make sure that you restart your web server or that you reload your configuration values.

Otherwise, these changes will not take effect.