What is the difference between the 'www' folder and 'htdocs' folder?

What is the difference between the 'www' folder and 'htdocs' folder?

  1. Blog
  2. 15 November 2026
  3. 3 min read

Stefan Bogdanescu

Founder & Senior Architect

The www vs. htdocs Confusion: What's Actually Happening on Your Server

When you install Apache, a folder named www often appears immediately in your directory structure. Conversely, tutorials frequently point to htdocs, which seems identical in function but carries historical weight and platform-specific nuances. Understanding the distinction isn't just about nomenclature; it is about grasping how web servers are configured to serve content and why different environments choose one path over another.

The core truth is that both directories serve as the default document root for Apache, meaning they define where the server looks for files when you type a URL into your browser. Whether you place an index.html file in /var/www/html or /opt/lampp/htdocs, the result is functionally the same: the web server serves those files to clients. The difference lies entirely in configuration and convention rather than inherent capability within the Apache software itself.

In a standard Linux distribution, such as Ubuntu or Debian, the default installation path for Apache typically defaults to /var/www/html. This directory is often colloquially referred to as www because it resides inside the broader /var/www hierarchy. The parent directory /var/www acts as a staging ground where you might organize projects by domain name (e.g., domain1.com, domain2.com), but html remains the active document root for your primary site. This separation is crucial for security and organization, allowing system administrators to isolate user content from the core system files.

On the other hand, htdocs is a legacy standard deeply entrenched in shared hosting environments and bundled local stacks like XAMPP. The term "htdocs" stands for "HTML documents," reflecting its original purpose as a container specifically for static web assets. In XAMPP installations, you will frequently encounter /opt/lampp/htdocs. This path was chosen to avoid conflicts with system directories and to provide a clear, isolated workspace for developers running local servers. When you access localhost on XAMPP, the Apache configuration explicitly points to this folder as the root, ignoring any files placed elsewhere unless manually configured otherwise.

The technical mechanism behind this is controlled by the DocumentRoot directive in your Apache configuration file (usually found in httpd.conf or apache2.conf). If you inspect the configuration, you will see a line resembling:

DocumentRoot "/var/www/html"

or for XAMPP:

DocumentRoot "C:/xampp/htdocs"

Changing this directive tells Apache to ignore its default behavior and serve files from a different location. However, blindly changing the path without updating the <Directory> permission blocks can lead to 403 Forbidden errors or security vulnerabilities. For instance, if you set DocumentRoot to your home directory but fail to update the associated Require all granted directive, Apache might reject requests due to missing read permissions on the specific folder structure.

There is also a subtle consideration regarding virtual hosts. In production environments, it is common practice to place multiple domains under /var/www, creating subdirectories like /var/www/example.com. Inside each of these, you might create a public_html or stick with html as the root. Some hosting providers prefer public_html because it aligns with older cPanel standards, where public_html was the default document root for user accounts. While Apache treats www, htdocs, and public_html interchangeably once configured, consistency within your deployment pipeline matters most.

If you are developing a modern PHP application using frameworks like Laravel, you might notice that the framework's internal structure often mirrors this concept. Laravel expects its public assets to be accessible via a specific directory (often named public). When deploying to a server with an Apache document root of /var/www/html, you would typically symlink or move the Laravel public folder to match the DocumentRoot. This ensures that URLs like yoursite.com/assets/css/style.css resolve correctly without exposing the framework's core files located in the project root.

Ultimately, choosing between www and htdocs is a matter of environment and convention. There is no technical advantage to one over the other in terms of performance or security; the choice depends on which path your server configuration expects. By understanding that these folders are simply configurable aliases for the document root, you can avoid unnecessary confusion when switching between local development stacks like XAMPP and production Linux servers.

Our network