Apache is a renowned and one of the most used web servers on Ubuntu/Other Linux systems. By default, only one default domain is configured with the Apache. What if you have to host multiple sites? Don’t worry. Apache allows you to host multiple sites. For that, you have to configure the Apache Virtual Hosts on your Ubuntu.
This post will briefly instruct you to configure the Apache Virtual Hosts on Ubuntu 24.04:
Outline:
- Prerequisites: Install and Configure Apache
- Step 1: Install Apache
- Step 2: Configure Apache
- How to Configure Apache Virtual Hosts on Ubuntu 24.04
- Step 1: Create a Root Directory/Document of Your Domain
- Step 2: Make www-data the Owner of the Root Directory
- Step 3: Create a Main Web Page Inside the Root Directory
- Step 4: Create a Configuration File for Virtual Host
- Step 5: Enable the Site
- Step 6: Check the Configurations
- Step 7: Test Your VirtualHost
- Tip: How to Disable the Apache Virtual Host on Ubuntu 24.04
Prerequisites: Install and Configure Apache
Since we are heading to configure the Apache virtual hosts, the Apache web server must be installed and configured. Just follow the below two-step procedure to install/configure it:
Step 1: Install Apache
Update the system’s package list and install Apache:
sudo apt install apache2

Step 2: Configure Apache
Apache web server needs to be permitted through a firewall. Apache has multiple profiles that offer different functionality. You need to permit one of these Apache profiles:
- Apache: Refers to HTTP and this profile opens Port 80.
- Apache Secure: For HTTPS Port 443 is linked with this profile.
- Apache Full: Combination of Both above profiles, i.e., includes the HTTP/HTTPS and the ports 810/443.
Let’s allow the ‘Apache Full’ profile using the command:
sudo ufw allow 'Apache Full'
Reload the firewall and check its status using the command:
sudo ufw reload sudo ufw status
Note: If you are using the “ufw” utility for the first time on your system, this will not be installed on your system. Install and enable it using the commands:
sudo apt install ufw sudo ufw enable
Before proceeding, check the functioning of the Apache Web Server, i.e., either check the status or run its default page on the browser:
sudo systemctl restart apache2 sudo systemctl status apache2
Once Apache is installed and configured, it’s time to configure the Virtual Hosts:
How to Configure Apache Virtual Hosts on Ubuntu 24.04
As discussed, Apache only allows you to configure multiple sites on your Ubuntu. You just have to create a document structure. The document structure includes the main root directory of the site, the main page of the site, and all the relevant data to build up a site. In short, document structure is the foundation of the virtual host. Then, you have to map this document structure on the Apache’s configuration so that Apache recognizes it.
Here are the steps that demonstrate the whole process:
Step 1: Create a Root Directory/Document of Your Domain
First, you need to create the root directory of your domain. This defines the document structure of your domain too:
sudo mkdir -p /var/www/lgenie/
Now, you need to put the domain-related data inside the root document structure.
Step 2: Make www-data the Owner of the Root Directory
Set the ownership of the newly created directory to the “www-data” user. It is recommended not necessary to use the “www-data” as its owner, as this system user manages and overlooks the Apache processes:
sudo chown -R www-data:www-data /var/www/lgenie/
Step 3: Create a Main Web Page Inside the Root Directory
Inside the main directory, create an index.html page, and write any HTML-based code. So that, it can be tested when configured:
<html> <head> <title>Welcome to Linux Genie!</title> </head> <body> <h1> You are Into the Apache Virtual Host Tutorial on Ubuntu 24.04 </h1> </body> </html>
Step 4: Create a Configuration File For Virtual Host
Now, you need to create a configuration file of the domain/site. The file needs to be created where Apache keeps the configuration files of the hosted sites. The path is “/etc/apache2/sites-available/”.
As an example, we are creating “genie.conf” and open it in edit mode:
sudo nano /etc/apache2/sites-available/genie.conf
Here, you need to put some sort of the following syntax inside that file:
- ServerAdmin: Email Address of the admin of the server.
- ServerName: What Fully Qualified Domain Name should your website answer to? For instance, to host linuxgenie on your Ubuntu, the ServerName should be LinuxGenie.
- DocumentRoot: It defines the directory where the website files are available.
- CustomLog: The CustomLog keeps the record of requests made to your web server.
- ErrorLog: It records any error reported during the Apache’s processing.
<VirtualHost *:80> ServerAdmin admin@lgenie.com ServerName LinuxGenie DocumentRoot /var/www/lgenie/ ErrorLog ${APACHE_LOG_DIR}/error.log CustomLog ${APACHE_LOG_DIR}/access.log combined </VirtualHost>
Note: To avoid any mistake, you can create a copy of the already available configuration file, i.e., /etc/apache2/sites-available/000-default.conf.
sudo cp /etc/apache2/sites-available/000-default.conf /etc/apache2/sites-available/<Name>.conf
Step 5: Enable the Site
Enable the newly created site, i.e., whose configuration file is “genie.conf”. Use the a2ensite script to enable the site, as follows:
sudo a2ensite genie.conf
Also, restart the Apache service after enabling the new site:
To keep the system clean, it is recommended to disable the default configuration named “000-default.conf”:
sudo a2dissite 000-default.conf
You can verify these changes by listing the content of the “sites-enabled” directory, i.e., “/etc/apache2/sites-enabled” the directory where the Apache-enabled sites are available:
ls /etc/apache2/sites-enabled
Note: You can also verify this by checking/listing the content of the “conf”
Step 6: Check the Configurations
It’s time to test the newly set configuration:
sudo apache2ctl configtest
Note: While testing, you might get the ServerName configuration warning. That is just a warning and does not have an impact on your system (working of Apache). However, you can fix it by adding a field “ServerName IP-Address” in the Apache configuration file (/etc/apache2/apache2.conf).
Step 7: Test Your VirtualHost
Restart the Apache services
sudo systemctl restart apache2
And here you go. Open your browser and navigate to the localhost or the IP address associated with it. The main page set in Step 3 would appear, as can be seen below:
That’s how you can set up Apache Virtualhost on Ubuntu 24.04.
Following the same steps, you can set up multiple Apache-based Virtual hosts.
Tip: How to Disable the Apache Virtual Host on Ubuntu 24.04
Follow the below steps to disable the configured Apache Virtual Host on Ubuntu 24.04:
Step 1: Check the Enabled Sites
List the enabled sites in the enabled-sites directory of Apache:
ls /etc/apache2/sites-enabled
Note down the site name/virtual host that you want to disable.
Step 2: Disable the Desired Virtual Host
Use the “a2dissite” Apache’s script and the name of the virtual host to disable:
sudo a2dissite <virtualhost>
Similarly, if you want to enable the default Apache or some virtual host, then you can use the “a2ensite” script:
sudo a2ensite <config-file-name>
That’s all from this guide.
Bottom Line
To configure the Apache virtual hosts on Ubuntu 24.04, you need to create the document root structure with the proper ownership. Then, create the main page of the web inside that directory. After these, map all the configurations inside the Apache configuration file. That’s all and your Apache virtual host will be active.
This post has listed the steps to set up virtual hosts on Ubuntu 24.04, codenamed Noble Numbat.

