htdocs

htdocs is the folder on your computer where Apache looks for website files to serve. When you type localhost in your browser, Apache serves whatever is in htdocs. If you put an index.html file in htdocs, that's your homepage. If you put a WordPress installation there, that's your local WordPress site. The name stands for "HyperText Documents" — a relic from when the web was all about hypertext.

Every local server stack uses this concept, but they call it different things and put it in different places. This causes real confusion when following tutorials that say "put your files in the web root" without specifying where that actually is.

Where Is htdocs on Your System?

StackFolder LocationWhat It's Called
XAMPP (Windows)C:\xampp\htdocs\htdocs
XAMPP (Mac)/Applications/XAMPP/htdocs/htdocs
XAMPP (Linux)/opt/lampp/htdocs/htdocs
WAMPC:\wamp64\www\www
MAMP/Applications/MAMP/htdocs/htdocs
LaragonC:\laragon\www\www
Linux Apache/var/www/html/html (inside www)
Nginx (default)/usr/share/nginx/html/html

Notice the inconsistency: XAMPP and MAMP call it htdocs, WAMP and Laragon call it www, and Linux Apache calls it html inside /var/www/. They all mean the same thing — the document root, the folder Apache serves files from.

How htdocs Maps to URLs

The relationship between file paths and URLs is straightforward once you understand it:

# File on disk → URL in browser

C:\xampp\htdocs\index.php          → http://localhost/
C:\xampp\htdocs\about.html         → http://localhost/about.html
C:\xampp\htdocs\blog\index.php     → http://localhost/blog/
C:\xampp\htdocs\mysite\style.css   → http://localhost/mysite/style.css

htdocs IS localhost. Everything inside htdocs is accessible via the browser at localhost/path-to-file. Everything outside htdocs is invisible to the web server — which is important for security. Your wp-config.php database credentials are safe because Apache won't serve files from parent directories.

Working with Multiple Projects

The simplest way to manage multiple websites is to create subfolders inside htdocs:

htdocs/
├── project-a/        → localhost/project-a
│   ├── index.php
│   └── style.css
├── project-b/        → localhost/project-b
│   ├── index.html
│   └── app.js
├── wordpress/         → localhost/wordpress
│   ├── wp-admin/
│   └── wp-content/
└── dashboard/         → localhost/dashboard (XAMPP default page)
    └── index.html

This works fine for most development. Each project gets its own folder and URL. The downside: your URLs have that extra path segment (localhost/project-a instead of just project-a.test). For cleaner URLs, you can set up virtual hosts — custom domain names that each point to a different folder.

Changing the Document Root

You don't have to use the default htdocs location. If you'd rather serve files from your Desktop, Documents folder, or a custom projects folder:

XAMPP

# Edit C:\xampp\apache\conf\httpd.conf
# Find these two lines and change both:
DocumentRoot "C:/xampp/htdocs"
<Directory "C:/xampp/htdocs">

# Change to your preferred folder:
DocumentRoot "C:/Users/YourName/Projects"
<Directory "C:/Users/YourName/Projects">

# Restart Apache in XAMPP control panel

MAMP

MAMP → Preferences → Web Server → Document Root → click the folder icon and select your preferred directory.

WAMP

Left-click the WAMP tray icon → Apache → httpd.conf → find and change the DocumentRoot line.

Common Beginner Mistakes

Putting files in the wrong folder. The most common mistake. If you put index.php in C:\xampp\ instead of C:\xampp\htdocs\, it won't be accessible via localhost. Always put files inside htdocs (or the equivalent for your stack).

Editing files inside htdocs with a text editor that doesn't save. Some editors (especially on Windows) save to a different location or create backup copies instead of overwriting. If changes don't appear in the browser, verify the file in htdocs actually changed.

PHP files showing code instead of executing. If you see raw PHP code in the browser (<?php echo "Hello"; ?>), Apache isn't processing PHP. Either Apache isn't running, or the file has the wrong extension (must be .php, not .html or .txt).

Forgetting the file extension in the URL. localhost/about won't work unless you have URL rewriting enabled (like WordPress does with .htaccess). Without rewriting, you need the full filename: localhost/about.php or localhost/about.html.

Permission issues on Linux/Mac. If you get "403 Forbidden" when accessing a file you just created, the file permissions might be wrong. Files in the document root need to be readable by the web server user (usually www-data or _www). Fix with: chmod 644 yourfile.php

htdocs in Production

On live Linux servers, the concept is the same but the folder is different. Apache's default document root is /var/www/html/, and Nginx uses /usr/share/nginx/html/. These are configured in the server's virtual host configuration files. In production, each website typically has its own document root (e.g., /var/www/mysite.com/public_html/) configured via virtual hosts.