Configuring virtual hosts in Apache allows you to host multiple websites on a single server. In this detailed guide, we will walk you through the process of adding an Apache virtual host for a new domain. By following these steps, you will be able to successfully set up and manage multiple websites on your server.

Step 1: Prepare the Environment:

  1. Ensure that you have Apache installed and running on your server. If not, install Apache by running the appropriate commands for your Linux distribution (e.g., sudo apt install apache2 for Ubuntu).
  2. Verify that your domain’s DNS settings point to the correct IP address of your server. You can do this by creating an “A” record in your domain registrar’s DNS control panel and adding your IP address see the image below for a sample.
Type           Host/Name                  Value/Content
A               @                          IP address
A              www                         IP address

Step 2: Create a Directory for Your New Domain:

  1. Determine the directory where you want to store the files for your new domain. For example, you can create a directory under the default document root (/var/www/html/) or choose a different location.
  2. Create the directory using the following command:
    • sudo mkdir -p /var/www/html/

Step 3: Configure the Virtual Host:

  1. Create a new virtual host configuration file using a text editor. For example:
    • sudo nano /etc/apache2/sites-available/
  2. Add the following configuration to the file:
<VirtualHost *:80>
    DocumentRoot /var/www/html/
    <Directory /var/www/html/>
        Options Indexes FollowSymLinks
        AllowOverride All
        Require all granted
    ErrorLog ${APACHE_LOG_DIR}/example.com_error.log
    CustomLog ${APACHE_LOG_DIR}/example.com_access.log combined
  1. Save the file and exit the text editor.

Step 4: Enable the Virtual Host:

  1. Create a symbolic link from the sites-available directory to the sites-enabled directory to enable the virtual host:
    • sudo ln -s /etc/apache2/sites-available/ /etc/apache2/sites-enabled/
  2. Reload Apache for the changes to take effect:
    • sudo systemctl reload apache2

Step 5: Test the Configuration:

  1. Open a web browser and enter your domain (e.g.,
  2. If you see the default Apache page or a “404 Not Found” error, ensure that the DNS settings are correctly configured and that the virtual host configuration matches the directory structure and domain settings.
  3. If you see the expected content for your new domain, the virtual host configuration is successfully set up.

Step 6: Repeat for Additional Domains:

  1. To add more domains, follow the same steps, creating separate virtual host configuration files for each domain.
  2. Ensure that the ServerName, ServerAlias, DocumentRoot, and log file paths are customized for each domain.

Conclusion: By following this comprehensive guide, you can successfully add an Apache virtual host for a new domain, allowing you to host multiple websites on your server. Remember to update DNS settings, configure virtual host files, enable and test the virtual host, and repeat the process for additional domains. With Apache’s virtual hosting capability, you can easily manage and serve multiple websites from a single server.