How to Install Apache with Virtual Hosts on Debian 10

Apache, popularly referred to as the Apache HTTP server, is a free and open-source cross-platform web server maintained by the Apache Foundation. It is the leading web server commanding a 35% market share on the internet with Nginx coming second with 24% .

Apache is highly reliable, flexible, easy to install and ships numerous features which make it popular amongst developers and Linux enthusiasts. Additionally, it is regularly maintained and updated by Apache foundation and this helps in fixing software bugs and improving its overall efficiency. By the time of penning down this article, the latest version of Apache is 2.4.39.

Read Also: Install Nginx with Server Blocks (Virtual Hosts) on Debian 10

In this guide, we will walk you through the steps on how to install Apache web server on Debian 10.


Before we get started, ensure the following requirements are met:

  1. An instance of Debian 10.
  2. A Fully Qualified Domain Name (FQDN) pointing to the server.
  3. In this guide, we use the domain pointing to a Debian 10 system with an IP address
  4. A good internet connection.

With our pre-flight check done, let’s get started

Step 1: Update the Debian 10 System Repository

The first step in installing Apache on Debian 10 is updating the system repositories. To achieve this, log in as a regular user and using sudo privileges run the command.

$ sudo apt update -y
Update Debian 10 Repository
Update Debian 10 Repository

Step 2: Install Apache on Debian 10

Installing Apache is a piece of cake and pretty straightforward. Once you have successfully updated the system repositories, run the command below to install Apache on Debian 10.

$ sudo apt install apache2 -y
Install Apache in Debian 10
Install Apache in Debian 10

Step 3: Checking the Status of Apache Webserver

After successful installation of Apache web server, it’s always recommended to check if the service is running. Most systemd Linux systems will start the service automatically upon installation.

To check the status of Apache webserver execute the command.

$ sudo systemctl status apache2
Check Apache Status
Check Apache Status

If the service is not running, start the service using the command.

$ sudo systemctl start apache2

To enable Apache Web server on boot execute the command.

$ sudo systemctl enable apache2

To restart Apache run.

$ sudo systemctl restart apache2

Step 4: Configure the Firewall to Allow HTTP Port

If UFW firewall is already configured, we need to allow the Apache service across the firewall so that external users can have access to the web server.

To achieve this, we need to allow traffic on port 80 on the firewall.

$ sudo ufw allow 80/tcp

To verify that the port has been allowed on the firewall, run.

$ sudo ufw status
Open Port 80 on UFW Firewall
Open Port 80 on UFW Firewall

Additionally, you can use the netstat command to verify the port as shown.

$ sudo netstat -pnltu
Verify Apache Listening Port
Verify Apache Listening Port

Step 5: Verify Apache HTTP Web Server

With all the settings in place, open your favorite web browser and browse your server’s IP address or FQDN as shown.

Check Apache Web Page
Check Apache Web Page

Step 6: Configuring Apache Web Server

With Apache web server already set up, its time to host a sample website.

The default Apache webpage file index.html is found at /var/www/html/ which is the webroot directory. You can host a single site or create virtual host files to host multiple sites.

To host a single site, you can modify the index.html file located on the webroot directory.

But first, make a backup of the file as shown.

$ sudo mv /var/www/html/index.html /var/www/html/index.html.bak

Now let’s create a new index.html file.

$ sudo nano /var/www/html/index.html

Let’s add some HTML sample content as shown.

        <title>Welcome to crazytechgeek</title>
        <h1>Howdy Geeks! Apache web server is up & running</h1>

Exit the text editor and restart the web server.

$ sudo systemctl restart apache2

Now reload your web browser and notice the changes to your new site.

Check Apache Website
Check Apache Website

Step 7: Creating Virtual Hosts on Apache

If you want your web server to host multiple sites, the best way to go around this is to create virtual hosts in Apache web server. Virtual hosts come in handy when you want to host multiple domains in a single server

First, we need to create a webroot directory for the domain

$ sudo mkdir -p /var/www/html/

Next, we shall assign the necessary permissions to the directory using the $USER variable.

$ sudo chown -R $USER:$USER /var/www/html/

Next, assign the necessary permissions of the webroot directory for the domain.

$ sudo chmod -R 755 /var/www/html/

Now using your favorite text editor, head out and create sample index.html file.

$ sudo nano /var/www/html/

Let’s add some HTML sample content as shown.

        <title>Welcome to</title>
        <h1>Howdy Geeks!</h1>

Save and exit the text editor.

Now, create a virtual host file for the domain using the command shown below.

$ sudo nano /etc/apache2/sites-available/

Now copy and paste the content below and replace the domain with your own domain.

<VirtualHost *:80>
    ServerAdmin [email protected]
    DocumentRoot /var/www/html/
    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined

Save and exit.

At this point, enable the virtual host file as shown.

$ sudo a2ensite

Now let’s disable the default site

$ sudo a2dissite 000-default.conf

To effect the changes, reload the apache webserver.

$ sudo systemctl restart apache2

Now reload your web server and notice the changes for your domain.

Verify Virtual Host on Apache
Verify Virtual Host on Apache

If you want to enable HTTPS on your website, read this article: How to Setup Free SSL Certificate for Apache on Debian 10.


We have come to the end of the tutorial. In this guide, you learned how to install Apache on Debian 10 and also configure virtual hosts to host other domains. Feel welcome to get back to us with your feedback.

James Kiarie
This is James, a certified Linux administrator and a tech enthusiast who loves keeping in touch with emerging trends in the tech world. When I'm not running commands on the terminal, I'm taking listening to some cool music. taking a casual stroll or watching a nice movie.

Each tutorial at TecMint is created by a team of experienced Linux system administrators so that it meets our high-quality standards.

Join the TecMint Weekly Newsletter (More Than 156,129 Linux Enthusiasts Have Subscribed)
Was this article helpful? Please add a comment or buy me a coffee to show your appreciation.


Leave a Reply
  1. Hello, Thanks for writing this guide.

    Can you help me with opening port 80, while I am using Debian on a laptop with internet access via hotspot running from a smartphone?

  2. Thanks – very useful step by step guide. I think that’s a typo in Step 4:

    $ sudo allow 80/tcp

    should be

    $ sudo ufw allow 80/tcp

Got Something to Say? Join the Discussion...

Thank you for taking the time to share your thoughts with us. We appreciate your decision to leave a comment and value your contribution to the discussion. It's important to note that we moderate all comments in accordance with our comment policy to ensure a respectful and constructive conversation.

Rest assured that your email address will remain private and will not be published or shared with anyone. We prioritize the privacy and security of our users.