Apache Web Server on Ubuntu: Install and Host a Static Site
Install Apache on Ubuntu, learn how /etc/apache2 is organised, and serve a static HTML template from /srv through a dedicated virtual host.

ON THIS PAGE
Apache HTTP Server is one of the most widely deployed web servers, and on a fresh Linux VM it exercises networking, file permissions and systemctl in a single setup. This guide installs Apache on Ubuntu, explains how its configuration is split across /etc/apache2, and publishes a static HTML template from /srv through a dedicated virtual host.
Prerequisites
- An Ubuntu server or VM with
sudoaccess. - Port 80 reachable from the machine you browse from.
Overview
A web server answers HTTP requests in front of your content or application. It serves static files, terminates TLS (HTTPS), writes access logs, and forwards requests to backend applications.
Apache and Nginx can both act as a reverse proxy: a server between clients and one or more backend servers that forwards requests and returns the responses, so clients never reach the backends directly. A reverse proxy is also the basis for load balancing and zero-downtime deployments.
Apache compared with Nginx
| Apache | Nginx | |
|---|---|---|
| How it handles connections | Multi-Processing Modules (MPMs): processes or threads per connection, or the event MPM | Event-driven: a few worker processes handle many connections each |
| Per-directory config | Supports .htaccess files | No .htaccess; all config is central |
| Extending it | Large set of modules, loaded with a2enmod on Ubuntu | Modules, many compiled in |
| Typical use | Traditional hosting, PHP apps, .htaccess-based sites | Static files, reverse proxy, high connection counts |
Both are mature and secure when patched; the choice usually follows the team's existing expertise.
Installation
$ sudo apt update
$ sudo apt install apache2
$ sudo systemctl enable --now apache2
$ systemctl status apache2
$ curl localhostenable --now starts Apache and enables it at boot. curl localhost returns the HTML of Ubuntu's default "It works" page. The systemctl commands are explained in Linux Commands.
How /etc/apache2 is organised
On Ubuntu and Debian, Apache's configuration is split into small files:
/etc/apache2/
├── apache2.conf main file, includes everything below
├── ports.conf ports to listen on (80, and 443 when SSL is enabled)
├── envvars environment variables: run user, log and PID paths
├── magic rules to detect a file's MIME type from its first bytes
├── mods-available/ all modules (*.load loads the code, *.conf configures it)
├── mods-enabled/ symlinks to the modules in use
├── conf-available/ extra global config snippets
├── conf-enabled/ symlinks to the snippets in use
├── sites-available/ one virtual host file per site
└── sites-enabled/ symlinks to the sites being servedThe *-available directories hold every installed option; the *-enabled directories hold symbolic links to the active ones. Manage those links with Ubuntu's helper commands rather than by hand:
| Enable | Disable | For |
|---|---|---|
a2ensite | a2dissite | Sites (virtual hosts) |
a2enmod | a2dismod | Modules, for example a2enmod rewrite |
a2enconf | a2disconf | Config snippets |
After any change, check the syntax and reload:
$ sudo apache2ctl configtest
$ sudo systemctl reload apache2Log rotation is not part of /etc/apache2. It is handled by the logrotate tool, using /etc/logrotate.d/apache2, which compresses and deletes old files in /var/log/apache2/ so logs do not fill the disk.
Host a static website
The site in this example is the free Tooplate HTML template 2103_central.
1. Find the download URL
The download button does not expose the zip URL. Open the browser developer tools, switch to the Network tab, click download, and copy the URL of the .zip request:

2. Download and copy the files
$ cd /tmp
$ wget <zip-url-from-devtools>
$ unzip 2103_central.zip -d /tmp/site
$ sudo mkdir -p /srv/mysite
$ sudo cp -r /tmp/site/2103_central/. /srv/mysite/Confirm the extracted folder name with ls /tmp/site; it matches the template name. /srv is the standard place for data a server serves (see Introduction to Linux).
3. Give Apache access to the files
Apache's worker processes run as the www-data user on Ubuntu, so that user must be able to read the files:
$ sudo chown -R www-data:www-data /srv/mysite4. Allow Apache to serve /srv
By default, Apache only serves files under /var/www and /usr/share. Ubuntu's apache2.conf already has a block for /srv, but it is commented out. Remove the # from these lines:
<Directory /srv/>
Options Indexes FollowSymLinks
AllowOverride None
Require all granted
</Directory>Without this, the site returns 403 Forbidden.
5. Create a virtual host
A virtual host tells Apache which directory to serve for a site. Copy the default virtual host and change DocumentRoot:
$ sudo cp /etc/apache2/sites-available/000-default.conf /etc/apache2/sites-available/mysite.conf
$ sudo vim /etc/apache2/sites-available/mysite.conf<VirtualHost *:80>
ServerAdmin webmaster@localhost
DocumentRoot /srv/mysite
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>6. Switch sites and reload
$ sudo a2ensite mysite.conf
$ sudo a2dissite 000-default.conf
$ sudo apache2ctl configtest
$ sudo systemctl reload apache2
$ curl localhostcurl localhost now returns the template's HTML, and the site loads in a browser at the VM's IP address.
Troubleshooting
| Symptom | Likely cause |
|---|---|
403 Forbidden | The <Directory /srv/> block is still commented out, or www-data cannot read the files |
| Still showing the default "It works" page | 000-default.conf is still enabled, or Apache was not reloaded |
| Apache will not start after a change | Syntax error; run sudo apache2ctl configtest and check /var/log/apache2/error.log |
Works with curl localhost but not from the host | VM network or firewall; check the VM's IP and that port 80 is reachable |
Key takeaways
- On Ubuntu, Apache's config lives in
/etc/apache2, split into*-availablefiles and*-enabledsymlinks. - Use
a2ensite,a2enmodanda2enconf(and theira2dis*partners) instead of making links by hand. - Serving from outside
/var/wwwneeds a<Directory>block that grants access. - Files must be readable by
www-data. - Run
apache2ctl configtestbefore every reload.
For everything else, the Apache HTTP Server 2.4 documentation and its virtual host guide are the official references.
Keep reading
- How ssh works
Ever wondered what actually happens behind the scenes when you open your terminal and type ssh user@server
- Essential Linux Commands for DevOps
A task-based Linux command reference: navigating and managing files, reading logs, grep, sed, cut and awk, redirection, Vim, services, and basic networking.
- tmux Cheat Sheet: Sessions, Windows, Panes and Copy Mode
A tmux reference for remote work: sessions that survive SSH drops, windows, split panes, copy mode, synchronized panes, and a minimal tmux.conf.