htdocs — Your Local Website Folder

The htdocs folder (short for "HyperText Documents") is where Apache looks for files to serve via localhost. When you run XAMPP, WAMP, or MAMP and put files in htdocs, they become accessible at http://localhost/ in your browser. It's essentially your local equivalent of a web server's public directory.

View htdocs in browser:
http://localhost →
htdocs folder structure showing how files map to localhost URLs

htdocs Location by Platform

Server Stackhtdocs Path
XAMPP on WindowsC:\xampp\htdocs\
XAMPP on macOS/Applications/XAMPP/htdocs/
XAMPP on Linux/opt/lampp/htdocs/
WAMP on WindowsC:\wamp64\www\
MAMP on macOS/Applications/MAMP/htdocs/
Laragon on WindowsC:\laragon\www\
Linux (Apache default)/var/www/html/

How URLs Map to Folders

Files and folders in htdocs become accessible via localhost URLs:

File LocationBrowser URL
htdocs/index.phphttp://localhost/
htdocs/test.htmlhttp://localhost/test.html
htdocs/mysite/http://localhost/mysite/
htdocs/blog/post.phphttp://localhost/blog/post.php
htdocs/wordpress/http://localhost/wordpress/

Quick Start: Create Your First Page

  1. Navigate to your htdocs folder
  2. Create a file called hello.php
  3. Add this code:
<?php
echo "Hello, localhost!";
echo "<br>";
echo "Current time: " . date("Y-m-d H:i:s");
?>
  1. Start Apache in XAMPP
  2. Open localhost/hello.php

Organizing Projects in htdocs

Create separate folders for each project to keep things organized:

htdocs/
├── index.php          → localhost/
├── project1/          → localhost/project1/
│   ├── index.php
│   └── style.css
├── project2/          → localhost/project2/
├── wordpress/         → localhost/wordpress/
└── laravel-app/       → localhost/laravel-app/public/

Installing WordPress in htdocs

  1. Download WordPress from wordpress.org
  2. Extract to htdocs/wordpress/
  3. Create database in phpMyAdmin
  4. Visit localhost/wordpress/
  5. Follow installation wizard
  6. Access admin at localhost/wordpress/wp-admin

Common htdocs Issues

403 Forbidden

Cause: No index file or directory listing disabled.

Fix: Create index.php or index.html in the folder.

File Not Found (404)

Cause: File not in htdocs or wrong path.

Fix: Verify file is in htdocs and URL matches file path.

PHP Code Shows as Text

Cause: Apache not running or PHP not configured.

Fix: Start Apache in XAMPP. Make sure file ends in .php

Changes Not Showing

Cause: Browser cache.

Fix: Press Ctrl+F5 (hard refresh) or clear browser cache.

Permissions (Mac/Linux)

If you get permission errors when editing files:

# Give yourself ownership (Mac/Linux)
sudo chown -R $USER /Applications/XAMPP/htdocs/

# Or make it writable
sudo chmod -R 755 /opt/lampp/htdocs/

Changing the Document Root

Want to use a different folder instead of htdocs? Edit Apache config:

  1. Open httpd.conf in your text editor
  2. Find DocumentRoot line
  3. Change path to your preferred folder
  4. Also change the <Directory> path below it
  5. Restart Apache

Location of httpd.conf:

  • XAMPP Windows: C:\xampp\apache\conf\httpd.conf
  • XAMPP Mac: /Applications/XAMPP/etc/httpd.conf