How to Allow Directory Listing in Apache

by

Hey there! Some links on this page may be affiliate links which means that, if you choose to make a purchase, I may earn a small commission at no extra cost to you. I greatly appreciate your support!

In this simple tutorial, I’ll show you how to allow directory listing in Apache. By enabling directory listings in Apache, you can browse through the files and folders on your server from a web browser.

You will need  root access to your server. If you have that, let’s jump into the tutorial.

Enable Directory Listing in Apache

Options Indexes allows directory listings in Apache. This is equivalent to Options +Indexes. Conversely, Options -Indexes disables directory listings in Apache. This is when you typically see the “Forbidden You don’t have permission to access this resource” error message.

Forbidden You don't have permission to access this resource.

To enable directory listing in Apache, find the configuration file for your website that’s typically located at /etc/apache2/sites-available/ and ends in *.conf. Add Options Indexes within the Directory block of concern.

<VirtualHost *:80>
    <Directory /home/tonyflor/domains/tonyteaches.tech/public_html/>
        Options Indexes
    </Directory>
</VirtualHost>

At a minimum, the only 3 lines of code you must add to your Apache configuration file is lines 2-4 from above. This allows directory listing for everything under /home/tonyflor/domains/tonyteaches.tech/public_html. You can also change the directory value and update the DocumentRoot to serve files from a different directory.

Either way, you can now browse to your IP address or domain name and see an “index of page”.

Directory listing in Apache pagePin

Additionally, a more complete way to allow directory listing in Apaches is as follows.

<VirtualHost *:80>
    <Directory /home/tonyflor/domains/tonyteaches.tech/public_html/>
        Options Indexes followSymLinks
        AllowOverride None
        Require all granted
    </Directory>
</VirtualHost>

In this example, the additional options do the following.

  • followSymLinks allows the following of symbolic links
  • AllowOverride None option prevents the .htaccesss file from disabling directory listing
  • Require all granted allows any IP address access without credentials

If you have any questions about enabling or disabling directory listings in Apache, let me know in the comments below.


Meet Tony

With a strong software engineering background, Tony is determined to demystify the web. Discover why Tony quit his job to pursue this mission. You can join the Tony Teaches Tech community here.

Leave a Comment


The reCAPTCHA verification period has expired. Please reload the page.

2