This workflow adds one static, name-based Apache site while leaving Ubuntu’s default site in place. It is deliberately local: the example uses a special-use .test name and sends that name in a curl Host header, so no public DNS change is needed. The procedure is documentation-derived; use a non-production server first and review each command before entering it.

Scope

Platform: Linux server
Version: Ubuntu Server 24.04 LTS
Distribution: Ubuntu 24.04 LTS

The goal is to create a document root at /var/www/example-site, add example.test as a name-based virtual host, enable that site, reload Apache, and confirm the result through the loopback address. Ubuntu 24.04 LTS is in standard security maintenance through May 2029. IANA lists .test as a special-use domain and applies that designation to its subdomains, which makes example.test a safer concrete name for this local exercise than an invented public domain.

A name-based virtual host lets multiple sites share one IP address. Apache first narrows a request by address and port, then compares the request hostname with ServerName and ServerAlias. Apache’s documentation recommends an explicit ServerName; the minimal useful site definition also needs a DocumentRoot.

This is not a public-production recipe. It does not configure DNS, TLS, firewall rules, application runtimes, or Internet exposure.

Prerequisites

Use an Ubuntu Server 24.04 LTS machine where Apache HTTP Server 2.4 is already installed and active. The account needs sudo access. Keep a separate administrator session open if this is a remote machine, and check that the two paths used below do not already exist.

Confirm the operating system, Apache version, service state, and unused paths:

lsb_release -ds
apache2ctl -v
systemctl is-active apache2
test ! -e /etc/apache2/sites-available/example-site.conf
test ! -e /var/www/example-site

The first command should identify Ubuntu 24.04 LTS. The service check should print active. Each test ! -e command is silent when its target is absent; a nonzero status means stop and choose a different site name or inspect the existing path. This avoids silently replacing a configuration or document root.

Commands

Create the document root with directory permissions that permit Apache to traverse and read it, then write a small static index file:

sudo install -d -m 0755 /var/www/example-site
printf '%s\n' '<!doctype html><html lang="en"><meta charset="utf-8"><title>Example site</title><h1>Apache virtual host is responding</h1></html>' | sudo tee /var/www/example-site/index.html >/dev/null
sudo chmod 0644 /var/www/example-site/index.html

Create a dedicated virtual-host file. The quoted here-document preserves Apache’s ${APACHE_LOG_DIR} variable instead of asking the shell to expand it. Separate access and error logs make later troubleshooting less ambiguous.

sudo tee /etc/apache2/sites-available/example-site.conf >/dev/null <<'EOF'
<VirtualHost *:80>
    ServerName example.test
    DocumentRoot /var/www/example-site
    ErrorLog ${APACHE_LOG_DIR}/example-site-error.log
    CustomLog ${APACHE_LOG_DIR}/example-site-access.log combined
</VirtualHost>
EOF

Enable only this new site, check the full Apache configuration, and reload the service:

sudo a2ensite example-site.conf
sudo apache2ctl configtest
sudo systemctl reload apache2

Do not continue to the reload if configtest reports an error. Apache documents configtest as a syntax parse that reports either success or detailed errors. Ubuntu documents a2ensite for enabling a file from sites-available and a2dissite for disabling it. A reload is less disruptive than a stop followed by a start because the service remains under systemd control while it rereads configuration.

Leaving 000-default.conf enabled is intentional. Requests whose host name does not match the new site can continue to use the existing default virtual host. This reduces the scope of the change and makes rollback straightforward.

Verification and expected outcome

First inspect Apache’s parsed virtual-host map, then request the new site locally while supplying its host name explicitly:

sudo apache2ctl -S
curl --fail --silent --show-error --header 'Host: example.test' http://127.0.0.1/

Expected outcome: apache2ctl -S lists example.test with /etc/apache2/sites-enabled/example-site.conf, and curl prints HTML containing Apache virtual host is responding.

The -S output matters because it shows how Apache interpreted the configuration, including which site is first for a given address and port. The curl request checks host-based selection and content delivery without relying on DNS. If curl returns the default Ubuntu page, inspect apache2ctl -S, confirm the enabled symlink exists, and verify that the request header and ServerName both read example.test.

Cautions

Ubuntu’s default Apache Listen 80 setting listens on all assigned addresses when no address is specified. This workflow does not change that setting. If the machine is reachable from other networks, port 80 may already be exposed according to the host firewall and upstream network controls. Treat the page as plain HTTP: it is unencrypted and unsuitable for credentials or private data.

The .test name is for this local check. Do not publish it in DNS or mistake this exercise for a public deployment. A real site needs a domain you control, correct DNS, HTTPS, renewal monitoring, access-log handling, patching, backups, and an exposure review.

Virtual-host ordering also matters. Apache uses the first matching name-based virtual host when no ServerName or ServerAlias matches. That is why the verification step checks the parsed map and sends an explicit host header. Review existing sites before changing the default site or adding aliases.

Rollback or removal

Disable the site, validate the remaining configuration, reload Apache, and only then remove the dedicated configuration and content created by this workflow:

sudo a2dissite example-site.conf
sudo apache2ctl configtest
sudo systemctl reload apache2
sudo rm -f /etc/apache2/sites-available/example-site.conf
sudo rm -f /var/www/example-site/index.html
sudo rmdir /var/www/example-site

Expected outcome: a2dissite reports that the site was disabled, configtest reports a valid configuration, and the exact site file and document root created above are gone. The default site remains enabled. If rmdir says the directory is not empty, stop and inspect it rather than deleting recursively; unexpected files may belong to another process or administrator.

After rollback, this optional local request shows what the remaining default virtual host serves:

curl --silent --show-error --header 'Host: example.test' http://127.0.0.1/ | head

Because the explicit example.test site is disabled, Apache will use the first remaining virtual host for port 80. That result confirms removal of the name match, but it is not a reason to expose the default site publicly.

Sources

  1. Canonical Canonical · Retrieved
  2. Canonical Canonical · Retrieved
  3. Apache Software Foundation Apache Software Foundation · Retrieved
  4. Apache Software Foundation Apache Software Foundation · Retrieved
  5. Apache Software Foundation Apache Software Foundation · Retrieved
  6. Internet Assigned Numbers Authority Internet Assigned Numbers Authority · Retrieved

Mira Halden

Mira Halden is TechNest's disclosed editorial pen name. The name identifies the editor responsible for the final review.

Process note: AI assisted with research organization and drafting; Mira Halden reviewed the sources, claims, and final wording. AI-use policy