Support Online
Skip to main content

Installing Apache Web Server on Debian 11

In this guide, you will learn how to install Apache HTTP Server on Debian 11, configure the firewall, and host multiple sites using virtual hosting.

Technical Summary (Phase 1)

Main Technical Topic: Installation and configuration of Apache HTTP Server on Debian 11 operating system. Also, Virtual Host configuration to host multiple websites.

Solves the Problem: Installing the Apache web server on Debian 11 allows developers to properly configure the firewall and host multiple sites on a single server.


What Will You Learn in This Guide?

  • Installation of Apache HTTP Server on Debian 11.
  • Do not allow HTTP traffic with UFW firewall.
  • Basic administrative commands of Apache: start, stop, restart and reload.
  • Hosting multiple sites using Virtual Host.
  • Recognizing Apache's important configuration files and directories.

1. Apache Web Server Installation (Debian 11)

1.1 Requirements

  • Debian 11 Virtual Server (Instance): A non-root user with sudo privileges and an active firewall (UFW).

1.2 Apache Installation

Apache is available in Debian's default software repositories. We can install with standard package management tools.

1. Update local package directory:

sudo apt update

This command updates the local package index.

2. Install the Apache2 package:


sudo apt install apache2
  • This command installs the Apache web server and all necessary dependencies.

2. Firewall Settings

  • Before testing Apache, we must edit the firewall settings to allow external access to web server ports.

2.1 List UFW application profiles:


sudo ufw app list
  • This command shows the ready-made profiles that Apache adds to UFW during installation.

  • Enable WWW profile that allows HTTP traffic:


sudo ufw allow 'WWW'

Check the change:


sudo ufw status

3. Checking the Web Server

1. For Apache's status, use the systemctl command:


sudo systemctl status apache2

3.1 To find out the public IP address of your server:


hostname -I
  • Or using the curl command:

sudo apt install curl
curl -4 icanhazip.com
  1. Enter your IP address in the browser:

http://sunucu_ip_adresiniz

  • You should see Apache's default page.

4. Apache Service Management**

  1. To stop the web server:

sudo systemctl stop apache2
  1. To start the server:

sudo systemctl start apache2
  1. To restart the service:

sudo systemctl restart apache2
  1. To reload without breaking connections when configuration changes are made:

sudo systemctl reload apache2
  1. We must use Virtual Host to host multiple websites on a single server.*

5.1 Creating a Directory Structure***

  1. Create the web root directory for our site:

sudo mkdir -p /var/www/ornek.com
  1. Assign directory ownership to your current user:*

sudo chown -R $USER:$USER /var/www/ornek.com
  1. To make sure the permissions are correct:

sudo chmod -R 755 /var/www/ornek.com

4. Creating a Test Page

  1. Create a sample index.html file in the new directory:

nano /var/www/ornek.com/index.html

2. Add HTML content:


<html>
<head>
<title>GenixNode'a Hos Geldiniz!</title>
</head>
<body>
<h1>Basarili! ornek.com Sanal Host'u calisiyor!</h1>
</body>
</html>

5. Configuring the Virtual Host File

  1. Create a new Virtual Host file:

sudo nano /etc/apache2/sites-available/ornek.com.conf

Add the configuration block:


<VirtualHost *:80>
ServerAdmin webmaster@localhost
ServerName ornek.com
ServerAlias www.ornek.com
DocumentRoot /var/www/ornek.com
ErrorLog $&#123;APACHE_LOG_DIR&#125;/error.log
CustomLog $&#123;APACHE_LOG_DIR&#125;/access.log combined
</VirtualHost>

6. Enabling and Testing Virtual Host

  1. Activate the new Virtual Host file:

sudo a2ensite ornek.com.conf
  • Disable default site:

sudo a2dissite 000-default.conf
  • Make sure there are no configuration errors:

sudo apache2ctl configtest
  • Restart Apache:

sudo systemctl restart apache2

7. Important Apache Files and Directories

7.1 Basic locations you need to know for Apache administration:

  1. Content Directories:
  • /var/www/html: Default web content.
  1. Server Configuration:
  • /etc/apache2: Main Apache configuration directory.

  • /etc/apache2/apache2.conf: Main global configuration file.

  • /etc/apache2/sites-available/: Site-based Virtual Host configurations.

  • Server Logs:

  • /var/log/apache2/access.log: All access requests.

  • /var/log/apache2/error.log: All errors.

Frequently Asked Questions (FAQ)

The table below contains clear and concise answers to the questions users are most curious about.

| Why is Fluent Bit preferred over Logstash? | It is much lighter, consumes low CPU/RAM. Ideal for small to medium sized servers. | | Can I send logs from more than one server? | Yes. Each instance can transmit logs to the same OpenSearch cluster via Fluent Bit. | | Do I have to separate index names? | Yes, separating access/error logs provides ease of analysis. | | Can I write IP address instead of host? | If you use TLS the hostname is more secure (certificate matching). | | Do I need to change the Nginx log format? | No. Fluent Bit automatically supports nginx parser. | | Why are the logs not visible? | Usually the Match filter is faulty or the index name was entered incorrectly. | | Why is the 25060 port important? | OpenSearch is the default TLS port in managed services. Firewall must be open. | | What does Suppress_Type_Name On do? | Disables the _type field, which is deprecated in OpenSearch 7+. | | Logs arrive late, why? | If the tail plugin is affected by file rotation, mem_buf_limit or Skip_Long_Lines settings may be required. | | Fluent Bit uses too much CPU, solution? | Refresh_Interval, Mem_Buf_Limit and Buffer_Chunk_Size should be optimized. |

Result

You have successfully installed the Apache web server on Debian 11, configured the firewall and created a Virtual Host suitable for hosting multiple sites. You are now ready to present your web content.

As a next step, you may consider installing PHP and MariaDB (LAMP stack) on Debian 11.

You can test this installed web server on the GenixNode platform right now!