How To Install Apache Web Server on Debian 12

This tutorial intends to teach you to Install Apache Web Server on Debian 12 Bookworm and Create Apache Virtual Host File. Apache is a popular and widely used web server available for free. Debian 12 ships with the latest release of Apache which is Apache 2.4.57.

How To Install Apache Web Server on Debian 12?

To complete this guide, you must have access to your server as a non-root user with sudo privileges and set up a basic firewall. To do this, you can follow this guide on Initial Server Setup with Debian 12 Bookworm.

Also, you need a domain name that is pointed to your server’s IP address.

Now follow the steps below to complete this guide.

Step 1 – How To Install Apache From Command Line on Debian 12?

First, you need to run the system update by using the command below:

sudo apt update

Then, use the following command to install the Apache webserver on Debian Bookworm:

sudo apt install apache2 -y

During the installation, your Apache server must be activated. To verify it, you can use the command below:

sudo systemctl status apache2

In your output, you should see:

● apache2.service - The Apache HTTP Server
     Loaded: loaded (/lib/systemd/system/apache2.service; enabled; preset: enab>
     Active: active (running) since Sat 2023-06-17 04:56:20 EDT; 5s ago
   Main PID: 1074 (apache2)
      Tasks: 55 (limit: 4653)
     Memory: 13.4M
        CPU: 84ms
     CGroup: /system.slice/apache2.service

Step 2 – How To Manage Apache Web Server?

When you are done with the Apache installation, you can learn some basic management commands.

You can stop your web server with the following command:

sudo systemctl stop apache2

To start it again you can use:

sudo systemctl start apache2

Also, you can stop and then start the service with:

sudo systemctl restart apache2

If you have made some configuration changes you need to reload your service after doing that with the following command:

sudo systemctl reload apache2

To disable the service run the following command:

sudo systemctl disable apache2

Then you can re-enable it to start the service every time the server boots:

sudo systemctl enable apache2

Step 3 – Adjust UFW Firewall For Apache on Debian 12

At this point, we assumed that you have enabled the UFW firewall from the requirements. Now you should modify the firewall settings to allow outside access to the default web ports. You must allow Apache HTTP port through the firewall. To do this, you can run the command below:

sudo ufw allow 'WWW'

Reload the UFW firewall to apply the changes:

sudo ufw reload

You can check your UFW status by using the command below:

sudo ufw status
Status: active

To                         Action      From
--                         ------      ----
WWW                  ALLOW       Anywhere
OpenSSH                    ALLOW       Anywhere
WWW (v6)              ALLOW       Anywhere (v6)
OpenSSH (v6)               ALLOW       Anywhere (v6)

Step 4 – Check Apache Web Server Status on Debian 12

At this point, you can verify your Apache installation by accessing the default page on your Debian 12.

For doing this, you need your server’s IP address. You can get your IP with the following command:

hostname -I

Or you can use the icanhazip tool to get your IP. Run the following command:

curl -4

Enter your server’s IP address in your favorite browser:


you will see the page like the image below:

Apache default page Debian 12

When you see this page it means that the Apache is working correctly. 

Step 5 – How To Create a Virtual Host File in Apache Debian 12?

At this point, you can start to create your first virtual host file in Apache. To do this, you can follow the steps below:

  • Create a directory for your domain under /var/www directory:
sudo mkdir /var/www/
  • Set ownership of the HTML directory with the $USER environmental variable:
sudo chown -R $USER:$USER /var/www/
  • To set up an Apache virtual host you need to set default permissions for your webroot:
sudo chmod -R 755 /var/www/
  • Create a sample index.html page using Vi editor:
sudo vi /var/www/

Add the following content to the file:

<title>Welcome to!</title>
<h1>Success! The virtual host is working!</h1>

When you are done, save and close the file.

  • Then, you need to create a sites-available directory:
sudo vi /etc/apache2/sites-available/

Add the following content to the file:

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

Save and close the file when you are finished.

  • Enable the file with the a2ensite tool:
sudo a2ensite
  • Disable the default site defined in 000-default.conf:
sudo a2dissite 000-default.conf
  • Test for configuration errors:
sudo apache2ctl configtest

You should see the following output:

Syntax OK
  • Restart your web server with the following command:
sudo systemctl restart apache2

Now you are ready to test your Apache virtual host on Debian 12 configuration:

You will see your Apache virtual host test page in the image below:

Apache web server virtual hosts

For more information, you can visit Apache HTTP Server Documentation.


At this point, you have learned to Install Apache Web server on Debian 12 Bookworm, Manage your Apache service, Adjust the UFW firewall for Apache, and Create an Apache virtual host file.

Hope you enjopy it. You may be interested in these articles:

How To Install MariaDB on Debian 12 Bookworm

Install Gnome Desktop Environment on Debian 12

How To Install MySQL on Debian 12 Bookworm


Please enter your comment!
Please enter your name here
Captcha verification failed!
CAPTCHA user score failed. Please contact us!
Latest Articles


Most Popular