How To

Install Apache on Ubuntu 20.04: Setup and Virtual Host Guide

Apache is one of the most widely used open-source web servers in the world. It is cross-platform, highly flexible, and can be extended with modules to handle SSL, caching, authentication, URL rewriting, and more. A large share of the internet runs on Apache.

This guide shows you how to install Apache on Ubuntu 20.04, open the firewall, verify the setup, and configure a virtual host for your domain.

<strong>Prerequisite:</strong>&nbsp;You need a user account with sudo access to follow these steps.

Install Apache on Ubuntu

Apache is available in the default Ubuntu repositories. On Ubuntu and Debian systems, the package and service are both called apache2. Install it with:

bashsudo apt updatesudo apt install apache2

The service starts automatically after install. Confirm it is running:

bashsudo systemctl status apache2

Look for active (running) in the output. The default web root directory is /var/www/html — this is where Apache serves files from by default.

To start, stop, or restart Apache at any time:

bashsudo systemctl start apache2sudo systemctl stop apache2sudo systemctl restart apache2

Open the Firewall

Apache listens on port 80 for HTTP and port 443 for HTTPS. Use the Apache Full UFW profile to open both ports at once:

bashsudo ufw allow 'Apache Full'

Verify the rule is active:

bashsudo ufw status

You should see Apache Full listed as allowed. The Apache Full profile covers both plain HTTP traffic and encrypted HTTPS traffic.

Verify the Apache Installation

Open your browser and go to:

http://your_server_ip_or_domain/

You should see the default Apache welcome page. It confirms the web server is installed and working. The page also shows key paths — where config files, log files, and the web root are located on your system.

Set Up a Virtual Host

A virtual host lets you run more than one website on a single server. Each site gets its own configuration file, which tells Apache:

  • Which domain name it handles (ServerName)
  • Where the website files are stored (DocumentRoot)
  • Where Apache writes error and access logs

Apache includes one virtual host by default. If you only host one site, place your files in /var/www/html and you are done.

For multiple sites, set up a separate virtual host for each domain. This example uses example.com. Replace it with your actual domain name.

Create the document root directory:

bashsudo mkdir -p /var/www/example.com

Set ownership to the Apache user so the server can read the files:

bashsudo chown -R www-data: /var/www/example.com

Create the virtual host config file:

bashsudo nano /etc/apache2/sites-available/example.com.conf

Paste this configuration:

apache&lt;VirtualHost *:80&gt;    ServerName example.com    ServerAlias www.example.com    ServerAdmin webmaster@example.com    DocumentRoot /var/www/example.com    &lt;Directory /var/www/example.com&gt;        Options -Indexes +FollowSymLinks        AllowOverride All    &lt;/Directory&gt;    ErrorLog ${APACHE_LOG_DIR}/example.com-error.log    CustomLog ${APACHE_LOG_DIR}/example.com-access.log combined&lt;/VirtualHost&gt;

Enable the site with a2ensite:

bashsudo a2ensite example.com

Check the config for syntax errors:

bashsudo apachectl configtest

If you see Syntax OK, restart Apache to apply the changes:

bashsudo systemctl restart apache2

Visit http://example.com in your browser. Your site should load from the document root you set.

<strong>Tip:</strong>&nbsp;To add HTTPS to your site, use&nbsp;<strong>Let's Encrypt</strong>&nbsp;with Certbot. It is free and works well with Apache on Ubuntu.

Apache is now installed and serving your site on Ubuntu. From here, you can deploy web applications, add virtual hosts for more domains, or enable modules to extend what Apache can do. Got questions? Leave a comment below.

Cyber Defence

Recent Posts

Add Swap Space on Ubuntu 20.04: Create, Enable, and Tune

Swap space is an area on disk that Linux uses when it runs out of physical…

9 minutes ago

Install Zoom on Ubuntu 20.04: Download, Setup, and Remove

Zoom is one of the most widely used video conferencing platforms. Zoom works on Windows, macOS,…

16 minutes ago

Install Webmin on Ubuntu 20.04: Complete Setup and Login Guide

Webmin is an open-source web-based control panel for Linux servers. It gives you a browser interface…

21 minutes ago

Install MariaDB on Ubuntu 20.04: Setup and Admin Access

MariaDB is an open-source relational database management system. It was created by the original MySQL developers…

34 minutes ago

Best OSINT Tools for Investigating Corruption 2026: Public Records and Link Analysis

Corruption investigations need accuracy, patience, and strong evidence. In 2026, OSINT tools can help researchers,…

45 minutes ago

Best OSINT Tools for Private Investigators 2026: Legal People and Asset Research

Private investigators use OSINT to collect public information, verify identities, review business connections, check public…

1 hour ago