Set up an Apache vhost on Ubuntu 20.04 and Debian 10

You can use virtual hosts (vhosts) to serve multiple domains without the need for additional Internet
Protocol (IP) addresses. With vhosts, the different pages display according to settings in the host file for the
particular site requested. This article describes how to create a vhost on Ubuntu® 20.04 and Debian® 10.

Note: In this article, you can replace the placeholder of with the domain for which you’re setting up the vhost.


  • A Linux® server running distribution Ubuntu version 20.04 or Debian version 10
  • Apache installed. Install it by using the following command: sudo apt install apache2
  • DNS pointing the site to the server’s IP
  • A user with SSH administrator privileges
  • Firewall configured to allow traffic on port 80

Set up a vhost

Use the following steps to set up an Apache® vhost:

  1. Create a new directory to store the website’s content. This directory is known as the root document folder in
    your Apache vhost configuration file.

     sudo mkdir -p /var/www/vhosts/
  2. Set the permissions for the new directory. Replace vhostuser in the username:vhostuser parameter with a user
    on the server who has access to the directory.

     sudo chown -R username:vhostuser /var/www/vhosts/
  3. Set read permissions to all users for the directory.

    sudo chmod -R 755 /var/www/vhosts/
  4. Create the configuration file for the vhost site.

    vi /etc/apache2/sites-available/
  5. Paste the following text into the file you created. Replace with your own site hostname.

    ServerAdmin [email protected]
    DocumentRoot /var/www/vhosts/
    <Directory /var/www/vhosts/>
        Options -Indexes +FollowSymLinks
        AllowOverride All
    ErrorLog ${APACHE_LOG_DIR}/
    CustomLog ${APACHE_LOG_DIR}/ combined

    Note: After you finish making the changes, save the file pressing the Esc key to switch to command mode and typing :xq to exit and save the changes.

  6. Create a symbolic link from the virtual host file to the sites-enabled directory to enable the new virtual host file using the a2ensite command.

    sudo a2ensite
  7. Check for issues. You should get a Syntax OK response.

    sudo apachectl configtest
  8. Restart Apache.

    sudo systemctl restart apache2
  9. If you want to see a test page, you can create a file named index.html in your root folder.

    vi index.html
  10. Paste the following text.

    <html lang="en" dir="ltr">
        <meta charset="utf-8">
        <title>vhost test for</title>
        <h1>Success! vhost!</h1>
  11. Save and exit the file.

  12. Navigate to to view the test page.