Beginner Fundamentals

DocumentRoot and Static Files

The DocumentRoot is the folder on disk that Apache maps to the root of your website. Files placed there become reachable through the browser.

Default Location

On Debian/Ubuntu the default is /var/www/html. A request for http://localhost/about.html maps to /var/www/html/about.html.

Setting DocumentRoot

DocumentRoot /var/www/mysite

When you change it, you must also allow access to the new directory:

DocumentRoot /var/www/mysite

<Directory /var/www/mysite>
    Require all granted
</Directory>

Create a Test Page

sudo mkdir -p /var/www/mysite
echo "<h1>Hello from Apache</h1>" | sudo tee /var/www/mysite/index.html

Index Files

When a request points to a folder, Apache looks for a default file defined by DirectoryIndex:

DirectoryIndex index.html index.php

Apply Changes

sudo apache2ctl configtest
sudo systemctl reload apache2

Now Apache serves any HTML, CSS, image, or other static file you drop into the DocumentRoot.