{"id":14232,"date":"2025-02-12T18:34:50","date_gmt":"2025-02-12T13:04:50","guid":{"rendered":"https:\/\/www.skynats.com\/?p=14232"},"modified":"2025-02-12T18:34:53","modified_gmt":"2025-02-12T13:04:53","slug":"how-to-disable-directory-listing-in-cpanel-with-apache","status":"publish","type":"post","link":"https:\/\/www.skynats.com\/blog\/how-to-disable-directory-listing-in-cpanel-with-apache\/","title":{"rendered":"How to Disable Directory Listing in cPanel with Apache"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\" id=\"h-introduction\" style=\"font-size:18px\">Introduction<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">When managing a website, prioritizing security is crucial. One common vulnerability is Apache&#8217;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 <a href=\"https:\/\/cpanel.net\/\" target=\"_blank\" rel=\"noopener\">cPanel<\/a> is an essential step to protect your website from potential threats.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">To prevent this security risk, it&#8217;s essential to disable directory listing on your cPanel server. In this guide, we\u2019ll walk you through the three best methods to secure your website by turning off directory listing effectively.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" style=\"font-size:18px\">Method 1: Using .htaccess (Per Website Basis)<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">1. Log in to cPanel.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">2. Navigate to File Manager and go to your website&#8217;s root directory (generally public_html).<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">3. Edit or create a .htaccess file:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Right-click on .htaccess and select Edit.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">If it doesn\u2019t exist, create one.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">4. Add the following line:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Options -Indexes<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">5. Save changes and close the editor.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">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.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" style=\"font-size:18px\">Method 2: Using WHM (Global Settings for All Domains)<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">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\u2019s how to do it:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">1. Log in to WHM as the root user.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">2. Go to Home \u2192 Service Configuration \u2192 Apache Configuration \u2192 Global Configuration.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">3. Scroll to the &#8220;Directory Options&#8221; section.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">4. Uncheck the &#8220;Indexes&#8221; option if it&#8217;s enabled.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">5. Save and Rebuild Apache Configuration when prompted.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">6. Restart Apache:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Navigate to Home \u2192 Restart Services \u2192 HTTP Server (Apache).<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Click Yes to confirm.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" style=\"font-size:18px\">Method 3: Using SSH (For Root Access)<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">1. Access the server via SSH as the root user.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">2. Edit the Apache configuration file:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>#vim \/etc\/apache2\/conf\/httpd.conf<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">3. Find the Directory Block and modify it:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;Directory \"\/home\">\n    Options -Indexes\n    AllowOverride All\n&lt;\/Directory><\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">4. Save the file and exit the editor.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">5. Restart Apache to apply changes:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>#systemctl restart httpd<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" style=\"font-size:18px\">Conclusion<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Disabling directory listing is a simple yet effective way to enhance your website\u2019s security. Whether you prefer using cPanel, WHM, or SSH, the above methods will help you secure your directories from unauthorized browsing.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">For maximum security, consider combining these steps with other server hardening techniques.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">If you need further assistance or have any questions about How to Disable Directory Listing in cPanel with Apache, feel free to contact our <a href=\"https:\/\/www.skynats.com\/blog\/\">support team<\/a> for expert guidance and help securing your website. We&#8217;re here to assist you every step of the way!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Introduction When managing a website, prioritizing security is crucial. One common vulnerability is Apache&#8217;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 [&hellip;]<\/p>\n","protected":false},"author":13,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5],"tags":[18,964],"class_list":["post-14232","post","type-post","status-publish","format-standard","hentry","category-blog","tag-cpanel","tag-disable-directory-listing-in-cpanel-with-apache"],"_links":{"self":[{"href":"https:\/\/www.skynats.com\/blog\/wp-json\/wp\/v2\/posts\/14232","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.skynats.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.skynats.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.skynats.com\/blog\/wp-json\/wp\/v2\/users\/13"}],"replies":[{"embeddable":true,"href":"https:\/\/www.skynats.com\/blog\/wp-json\/wp\/v2\/comments?post=14232"}],"version-history":[{"count":0,"href":"https:\/\/www.skynats.com\/blog\/wp-json\/wp\/v2\/posts\/14232\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.skynats.com\/blog\/wp-json\/wp\/v2\/media?parent=14232"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.skynats.com\/blog\/wp-json\/wp\/v2\/categories?post=14232"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.skynats.com\/blog\/wp-json\/wp\/v2\/tags?post=14232"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}