Apache server is one of the most popular and open source web servers that is developed and maintained by Apache Software Foundation. Apache is by far the most commonly used Web Server application in Linux operating systems, but it can be used on nearly all OS platforms Windows, MAC OS, OS/2, etc. It enables the developers to publish their content over the internet

In this article, we will explain how to install and configure the Apache webserver on Debian 10 OS.

Follow the steps below to install Apache2 on your system using the Ubuntu official repositories.

Step 1: Update system repositories

First, we will need to update the package repositories in our OS. For that, run the following command in Terminal as sudo:

$ sudo apt update

When prompted for the password, enter the sudo password.

How to Install and Configure Apache Web Server on Debian 10 Debian linux shell

Step 2: Install Apache 2 with the apt command

Next in this step, install the Apache2 web server using the following command:

$ sudo apt install apache2

How to Install and Configure Apache Web Server on Debian 10 Debian linux shell

You will be provided with a Y/n option to continue the installation. Hit y to continue.

Step 3: Verify the Apache installation

Once the installation is completed, you can view the Apache version installed by running the following command in Terminal. This way you can also verify the Apache is successfully installed on your system.

$ apache2 -version

How to Install and Configure Apache Web Server on Debian 10 Debian linux shell

If the firewall is running on your system, you will need to allow certain web ports so that external users can access it. For that, run the following commands in Terminal:

$ sudo ufw allow 80/tcp
$ sudo ufw allow 443/tcp

Then run the following command to verify if the ports have been allowed.

$ sudo ufw status

Step 1: Verify that the Apache service is running

After the installation, the Apache web service starts running automatically. However to make sure, run the following command in Terminal:

$ sudo systemctl status apache2

Step 2: Verify Apache Web server

You can verify if the Apache web server is working fine by requesting a web page from the Apache web server.

Execute the below command in Terminal to find the IP address of your server.

$ hostname -I

Once you find the IP address, type http:// followed by the IP address of your web server as follows:

http://server_IP

By entering the above IP address, you will see the following default Apache page.

How to Install and Configure Apache Web Server on Debian 10 Debian linux shell

Virtual hosts in Apache enables you to run multiple websites on a single server. We will set up here virtual host in the Apache webserver. For that, we will first create a website named testdomain.info using the server block that is available in Apache by default.

Step 1: Set up a domain name

First, we will create a directory at /var/www for our virtual host testdomain.info.For that, we will use the following command:

(Note: Replace testdomain.info with your own domain name.)

$ sudo mkdir -p /var/www/testdomain.info/html

Now change the ownership and permissions using the following commands:

$ sudo chown -R $USER:$USER /var/www/testdomain.info /html
$ sudo chmod -R 755 /var/www/testdomain.info

Now we will create a sample index page to test our testdomain.info site. To do so, we will create an HTML file using the nano editor as follows:

$ nano /var/www/testdomain.info/html/index.html

Add the following lines for the index page:


Welcome to the page testdomain.info!


You got Lucky! Your testdomain.info server block is up!

How to Install and Configure Apache Web Server on Debian 10 Debian linux shell

Once done, press Ctrl O to save and then Ctrl X to exit the file.

Now we will create a virtual host file that will serve the contents of your server using the following command:

$ sudo nano /etc/apache2/sites-available/testdomain.info.conf

Now add the following configuration details for your domain name:

  ServerAdmin [email protected]
  ServerName testdomain.info
  ServerAlias www.testdomain.info
  DocumentRoot /var/www/testdomain.info/html
  ErrorLog ${APACHE_LOG_DIR}/error.log
  CustomLog ${APACHE_LOG_DIR}/access.log combined

How to Install and Configure Apache Web Server on Debian 10 Debian linux shell

Once done, press Ctrl O to save and then Ctrl X to exit the file.

Step 2: Enable the domain configuration file

Now enable the virtual host file using the following command:

$ sudo a2ensite testdomain.info.conf

How to Install and Configure Apache Web Server on Debian 10 Debian linux shell

Now let’s disable the default Apache configurations using the following command:

$ sudo a2dissite 000-default.conf

How to Install and Configure Apache Web Server on Debian 10 Debian linux shell

To apply the changes, restart Apache2 service using the following command:

$ sudo systemctl restart apache2

Step 3: Test for errors

Now test the configuration for any syntax errors:

$ sudo apache2ctl configtest

In case there is no error, you will receive the following output.

How to Install and Configure Apache Web Server on Debian 10 Debian linux shell

In some cases, you might receive the following error:

How to Install and Configure Apache Web Server on Debian 10 Debian linux shell

To resolve this error, edit the servername.conf file by executing the following command:

$ sudo nano /etc/apache2/conf-available/servername.conf

Add the following line in it:

ServerName testdomain.info

How to Install and Configure Apache Web Server on Debian 10 Debian linux shell

Once done, press Ctrl O to save and then Ctrl X to exit the file.

After that run the following command:

$ sudo a2enconf servername

How to Install and Configure Apache Web Server on Debian 10 Debian linux shell

Now reload the Apache2:

$ systemctl reload apache2

Once done, again run the following command to test the configuration file:

$ sudo apache2ctl configtest

Now you will see the error has removed.

Step 4: Test if Apache is serving your domain name

Now open the browser and navigate to :

http://testdomain.info

Replace testdomain.info with your own domain name.

The following index page shows now you are able to access all your websites.

How to Install and Configure Apache Web Server on Debian 10 Debian linux shell

Here are some of the most common commands that can be used for managing Apache services:

Use the following command to start the Apache server:

$ sudo systemctl start apache2

Use the following command to stop the Apache server:

$ sudo systemctl stop apache2

Use the following command to restart the Apache server:

$ sudo systemctl restart apache2

Use the following command to reload the Apache server:

$ sudo systemctl reload apache2

Use the following command to always start the service on boot:

$ sudo systemctl enable apache2

Use the following command to disable the Apache server:

$ sudo systemctl disable apache2

In this article, we have learned how to install and configure the Apache web server on a Debian OS. We have done some basic configurations that include changes to the firewall, setting up the virtual host, and how to manage the Apache services using some commands. I hope it has given you a basic overview of how to use Apache to host the websites properly.