How To

Apache Virtual Hosts Setup on Ubuntu 20.04 Made Easy

Managing multiple websites on a single server is a common requirement for developers, businesses, and hosting providers. Apache Virtual Hosts make this possible by allowing one Apache web server instance to serve multiple domains independently. Each website can have its own document root, logging configuration, and security settings while sharing the same server resources.

This guide explains how to configure Apache Virtual Hosts on Ubuntu 20.04 and host multiple websites efficiently.

What Are Apache Virtual Hosts?

Apache Virtual Hosts are configuration blocks that enable Apache to respond differently based on the requested domain name. Instead of deploying separate servers for every website, administrators can host several domains on one machine.

Key advantages include:

  • Hosting multiple websites on one server
  • Separate document roots for each domain
  • Independent logging and security settings
  • Easier server management
  • Better resource utilization

Before proceeding, ensure Apache is installed and your domain names point to the server’s public IP address.

Creating the Website Directory Structure

The first step is creating a dedicated directory for each website. This directory acts as the document root where website files are stored.

A common structure looks like this:

/var/www/├── example1.com│   └── public_html├── example2.com│   └── public_html

Each domain receives its own folder, making website management cleaner and more organized.

Inside the document root, create a simple index.html file to verify that the website loads correctly once the virtual host is enabled.

It is also recommended to assign ownership of the website files to the Apache web server user (www-data) to avoid permission-related issues.

Configuring Apache Virtual Hosts

Once the directory structure is ready, create a virtual host configuration file inside Apache’s sites-available directory.

Each configuration typically defines:

  • Server name
  • Domain aliases
  • Document root
  • Directory permissions
  • Error logs
  • Access logs

For example, a virtual host can specify the primary domain and its www version while directing Apache to serve files from a specific website folder.

This separation allows every hosted website to maintain its own environment without interfering with others.

Enabling Apache Virtual Hosts

After creating the configuration file, the next step is enabling it.

Ubuntu provides a convenient utility that activates virtual host configurations by creating symbolic links between the sites-available and sites-enabled directories.

Before applying changes, always validate the configuration to detect syntax errors. Running a configuration test helps prevent Apache startup failures caused by incorrect settings.

If the test reports no issues, restart the Apache service to load the new virtual host configuration.

Managing Multiple Domains Efficiently

One of the biggest strengths of Apache Virtual Hosts is scalability. Adding another website simply requires:

  1. Creating a new document root.
  2. Adding website files.
  3. Creating a new virtual host configuration.
  4. Enabling the configuration.
  5. Restarting Apache.

This process can be repeated for any number of domains hosted on the same server.

Security and Best Practices

For a more secure environment:

  • Disable directory listing when unnecessary.
  • Use individual log files for each website.
  • Implement HTTPS with SSL certificates.
  • Restrict file permissions appropriately.
  • Regularly update Apache and Ubuntu packages.

These practices improve both security and maintainability.

Conclusion

Apache Virtual Hosts provide a powerful and flexible way to host multiple websites on a single Ubuntu 20.04 server. By organizing separate document roots, configuring dedicated virtual host files, and following proper security practices, administrators can efficiently manage multiple domains without deploying additional servers. Whether you’re running personal projects or production websites, Apache Virtual Hosts remain one of the most effective features of the Apache web server.

Cyber Defence

Recent Posts

Best OSINT Websites and Tools 2026: Browser-Based Research Kit

Not every OSINT task needs a terminal, script, or advanced Linux setup. In 2026, many…

56 minutes ago

Best OSINT Tools and Frameworks 2026: Build a Complete Investigation Workflow

The best OSINT tools and frameworks 2026 are not useful only because they collect public…

1 hour ago

Minecraft Server Ubuntu: Complete Setup Guide for 20.04

Running a Minecraft Server Ubuntu environment is one of the best ways to create a…

1 hour ago

Install TeamViewer Ubuntu – Easy Setup Guide for 20.04

Remote support and desktop access have become essential for businesses, IT teams, and individual users.…

1 hour ago

Install Curl Ubuntu: Quick Setup and Usage Guide

If you need to Install Curl Ubuntu systems for downloading files, testing APIs, or transferring…

1 hour ago

Install TensorFlow Ubuntu: Complete Setup Guide for 20.04

Machine learning developers often choose Ubuntu because of its stability, performance, and strong Python ecosystem.…

2 hours ago