Introduction
When managing a website, prioritizing security is crucial. One common vulnerability is Apache’s default setting that enables directory listing. This means that if an index file (such as index.html or index.php) is absent, visitors can access a complete list of files and folders within that directory. This unintentional exposure of sensitive files can put your site at risk. Learning How to Disable Directory Listing in cPanel is an essential step to protect your website from potential threats.
To prevent this security risk, it’s essential to disable directory listing on your cPanel server. In this guide, we’ll walk you through the three best methods to secure your website by turning off directory listing effectively.
Method 1: Using .htaccess (Per Website Basis)
1. Log in to cPanel.
2. Navigate to File Manager and go to your website’s root directory (generally public_html).
3. Edit or create a .htaccess file:
Right-click on .htaccess and select Edit.
If it doesn’t exist, create one.
4. Add the following line:
Options -Indexes
5. Save changes and close the editor.
Verify: Visit a directory without an index file (e.g., http://yourdomain.com/folder/). You should see a 403 Forbidden error instead of a directory listing.
Method 2: Using WHM (Global Settings for All Domains)
If you need to apply server-wide changes without modifying individual domain settings, WHM offers a centralized way to configure all domains on the server. Here’s how to do it:
1. Log in to WHM as the root user.
2. Go to Home → Service Configuration → Apache Configuration → Global Configuration.
3. Scroll to the “Directory Options” section.
4. Uncheck the “Indexes” option if it’s enabled.
5. Save and Rebuild Apache Configuration when prompted.
6. Restart Apache:
Navigate to Home → Restart Services → HTTP Server (Apache).
Click Yes to confirm.
Method 3: Using SSH (For Root Access)
1. Access the server via SSH as the root user.
2. Edit the Apache configuration file:
#vim /etc/apache2/conf/httpd.conf
3. Find the Directory Block and modify it:
<Directory "/home">
Options -Indexes
AllowOverride All
</Directory>
4. Save the file and exit the editor.
5. Restart Apache to apply changes:
#systemctl restart httpd
Conclusion
Disabling directory listing is a simple yet effective way to enhance your website’s security. Whether you prefer using cPanel, WHM, or SSH, the above methods will help you secure your directories from unauthorized browsing.
For maximum security, consider combining these steps with other server hardening techniques.
If you need further assistance or have any questions about How to Disable Directory Listing in cPanel with Apache, feel free to contact our support team for expert guidance and help securing your website. We’re here to assist you every step of the way!