Tutorials  /  Ubuntu

How To Configure Apache Web Server on an Ubuntu or Debian VPS

Ccentron Redaktion · January 2025 ·4 min read ·Ubuntu, Tutorial

Introduction

Apache is one of the most popular web servers on the internet. It is used to serve more than half of all active websites. Although there are many viable web servers that will serve your content, it is helpful to understand how Apache works because of its ubiquity.

This article will examine some general configuration files and the options that can be controlled within them. This article will follow the Ubuntu/Debian layout of Apache files, which is different from how other distributions build the configuration hierarchy.

VM

Matching infrastructure at centron

Ubuntu servers without your own hardware: ccloud³ VMs with full root access from €3.12 per month, billed by the hour and ready in seconds. Rent a cloud server →

Prerequisites to Configure Apache Web Server

If you are using Ubuntu version 16.04 or below, we recommend you upgrade to a more recent version since Ubuntu no longer provides support for these versions. This collection of guides will help you upgrade your Ubuntu version.

  • A server running Ubuntu, along with a non-root user with sudo privileges and an active firewall.
  • Apache installed on your server. Refer to our tutorial on How to Install the Apache Web Server on Ubuntu.

5 Steps to Configure Apache Web Server on Ubuntu

  1. The Apache File Hierarchy
  2. Exploring the apache2.conf File
  3. Set Apache Global Configurations
  4. Setup Apache Virtual Host File
  5. Enable Sites and Modules

Step 1: The Apache File Hierarchy

Apache keeps its main configuration files within the /etc/apache2 folder. Use this command to list the files:

Code
ls -f /etc/apache2

The directory contains:

  • apache2.conf: The main configuration file for the server.
  • ports.conf: Specifies the ports for virtual hosts.
  • sites-available/ and sites-enabled/: Manage virtual host configurations.
  • conf-available/ and conf-enabled/: Contain unattached configuration fragments.
  • mods-enabled/ and mods-available/: Manage optional modules.

Step 2: Exploring the apache2.conf File

The main configuration details for your Apache server are in the /etc/apache2/apache2.conf file. Open it with:

Code
sudo nano /etc/apache2/apache2.conf

The file is divided into sections for global settings, default server configuration, and virtual hosts. It uses Include directives to dynamically generate an overarching configuration file at startup.

Step 3: Set Apache Global Configurations

Modify options such as:

  • Timeout: Reduce from 300 to between 30 and 60 seconds for better performance.
  • KeepAlive: Set to On to handle multiple requests per connection.
  • MaxKeepAliveRequests: Set to 100 or 0 for unlimited requests.
  • KeepAliveTimeout: Default is 5 seconds.

Step 4: Update Apache Virtual Host File

Open the default virtual host file:

Code
sudo nano /etc/apache2/sites-available/000-default.conf

Adjust directives like ServerName and DocumentRoot to match your domain and content directory. Use ServerAlias to define alternate paths, such as www.your_domain.com.

Step 5: Enabling Sites and Modules

Enable a virtual host:

Code
sudo a2ensite your_domain

Restart Apache:

Code
sudo systemctl restart apache2

Enable a module:

Code
sudo a2enmod info

Disable a module:

Code
sudo a2dismod info

Conclusion to Configure Apache Web Server

Apache is versatile and modular, allowing you to tailor configurations to your needs. This guide provided a foundation to help you confidently explore and modify Apache’s configuration files. For specific options, consult the detailed comments in the provided files or the Apache documentation.

Jetzt 200 € Guthaben sichern

Testen Sie Ihr Setup auf ccloud³

Registrieren Sie sich in der ccloud³ und erhalten Sie 200 € Startguthaben für Ihr Projekt – z. B. für eine PostgreSQL-VM mit automatischen Backups.

centron Redaktion Technische Redaktion

Das Redaktionsteam von centron schreibt Anleitungen aus dem Betriebsalltag: getestet auf unserer eigenen Plattform, betrieben im Rechenzentrum in Hallstadt bei Bamberg.

Kategorie Ubuntu
Teilen
Noch offene Fragen?

Our team will help you with your specific setup - in German or English, by people who run the platform themselves.

War dieses Tutorial hilfreich?

Your answer is stored anonymously and helps us improve our tutorials.

Kommentare

No comments yet - be the first to ask a question about this tutorial.

Sign in to comment

Comments are open to centron customers. Sign in to your account to ask a question about this tutorial.

Weiterlesen

Das könnte Sie auch interessieren

Jetzt kostenlos anfangen

Melden Sie sich an und erhalten Sie in den ersten 60 Tagen ein Guthaben von 200 € bei centron.

Dieses Werbeangebot gilt nur für neue Konten. Angebot ausschließlich für Gewerbetreibende.

Jetzt loslegen Sales kontaktieren