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

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

Posted on |

Apache is a widely used web server on the internet. It serves more than half of all current websites. Although there are other potential web servers that may deliver your content, understanding how Apache works is beneficial due to its widespread use.

This article will look at several common configuration files and the settings that may be set within them. This post will use the Ubuntu/Debian Apache file structure, which differs from how other distributions construct the configuration hierarchy.

All apache web server configuration

Apache should be installed on your server before you begin researching Apache settings. Follow our How to Install the Apache Web Server on Ubuntu 20.04 guide or our How to Install the Apache Web Server on Ubuntu 20.04 instruction to discover how.

The Apache File System Configuration

The main configuration files for Apache are maintained in the /etc/apache2 folder. The following command will list all of the files in this folder:

ls -f /etc/apache2


Sites-available sites-enabled mods-available ports.conf magic mods-enabled conf-enabled conf-available This directory contains a lot of plaintext files and subdirectories. Here are some places you should be familiar with:

Apache conf: This is the server’s primary configuration file. Almost all setup may be done inside this file, although it is advised that separate, dedicated files be used for ease. This file will establish defaults and act as the server’s primary interface for reading configuration data.

ports.conf: This file specifies the ports on which virtual hosts should listen. If you are setting SSL, double-check that this file is accurate.

sites-available/ and sites-enabled/: Virtual host file settings are stored in the sites-available directory. This folder’s configurations will determine which material is provided for which requests. This is accomplished by connecting to the sites-enabled directory, which contains active virtual host configuration files. When Apache begins or reloads, it scans the configuration files and links in the sites-enabled directory and generates a complete configuration.

conf-available/ and conf-enabled/: These folders contain configuration pieces that are not linked to virtual host configuration files.

mods-enabled/ and mods-available/: These folders define modules that may be loaded selectively. The folders are divided into two parts: files that end in.load, which include fragments that load certain modules, and files that end in.conf, which hold the configurations of these modules.

Apache setup does not occur in a single monolithic file, but rather via a modular design in which new files may be added and adjusted as needed.

Exploring the Apache2.conf File

The main configuration details for your Apache server are held in the /etc/apache2/apache2.conf file. This file is divided into three main sections:

  • Configuration for the global Apache server process
  • Configuration for the default server
  • Configuration of virtual hosts.
  • Open this file with your preferred text editor. The following example uses nano:

sudo nano /etc/apache2/apache2.conf

This file is used to configure global definitions in Ubuntu and Debian. The Include directive is used to manage the setting of the default server and virtual hosts. The Include directive instructs Apache to read additional configuration files and insert them into the current file at the position where the statement appears. As a result, on starting, Apache builds an overall configuration file dynamically.

This file contains a variety of Include and IncludeOptional statements. These directives load module definitions, the ports.conf document, the conf-enabled/ directory’s individual configuration files, and the sites-enabled/ directory’s virtual host definitions:


IncludeOptional mods-enabled/*.load

IncludeOptional mods-enabled/*.conf

Include ports.conf

IncludeOptional conf-enabled/*.conf

IncludeOptional sites-enabled/*.conf

Global Configurations

In the Global Configuration, you may wish to change the following settings:


By default, this parameter is set to 300. This means that the server has 300 seconds to process each request. This time can be safely lowered to 30 to 60 seconds.


If this option is enabled, each connection will be able to handle several requests from the same client. If this is set to Off, each request must establish a new connection, which might result in substantial overhead depending on your configuration and traffic scenario.


This determines how many requests each connection will process before expiring. Keeping this number high will allow Apache to more effectively offer material to each client. The default value is set to 100. If this value is set to 0, Apache will be able to serve an unlimited number of requests for each connection.


This option indicates how long to wait for the next request once the previous one has been completed. If the timeout threshold is reached apache config file, the connection will be terminated through Dataservermarket. This implies that the server will create a new connection the next time content is requested to handle the request for the material that makes up the page the client is browsing. The default value is 5.

You can exit this configuration file after inspecting its contents by clicking CTRL+X.

Multi-Processing Modules

Apache’s modular design is extended with a Multi-Processing Module (MPM). MPMs are in charge of listening, guiding, and apache config file managing various network requests through Dataservermarket. Using the following command, you may determine which part your Apache installation was compiled in:

apache2 -L


Compiled in modules:









You can check the MPM type on your server with the a2query -M command:

a2query -M



The output reveals that the event MPM is used on this server. Your installation may have multiple to choose from through Dataservermarket, but only one can be selected.

Virtual Host File

The default virtual host declaration can be found in a file called 000-default.conf within the sites-available/ directory. You can learn about the general format of a virtual host file by examining apache config file this file.

Open the file with the following command:

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


<VirtualHost *:80>

ServerAdmin webmaster@localhost

DocumentRoot /var/www/html

ErrorLog ${APACHE LOG DIR}/error.log

CustomLog ${APACHE LOG DIR}/access.log combined

The default virtual host is set up to handle any HTTP requests on port 80, which is the standard HTTP port. This is stated in the declaration header as *:80, which means port 80 on any interface through Dataservermarket. This does not necessarily imply that it will process every request to the server on this port apache config file. Apache employs the most specific virtual host definition that corresponds to the request. If a more explicit definition existed, it may override this apache config one. You may exit the file after reviewing it by clicking CTRL+X.

Virtual Host Configuration Options

The following options are set within the virtual host definition outside of any other lower level sub-declaration through Dataservermarket. They apply to the whole virtual host. To start, open up the security.conf file apache config within the conf-available/ directory:

sudo nano /etc/apache2/conf-available/security.conf

This file contains the Server Signature directive, which allows you to define a contact email to be used in the event of a server failure. To show the server admin email address apache config file, change where is apache config the default setting from On to EMail. If you change this option, be sure you are willing to receive mail:


ServerSignature EMail

By using CTRL+X, you may exit the file. After modifying a configuration file, you will be prompted to through Dataservermarket validate your changes. Press Y to save the changes to your file, or N to remove them.

You may include a ServerName directive in your virtual host file that defines the domain name or IP address that this request should handle. This is the option that would give the virtual apache config host more specificity, allowing it to override the default definition if it matched the ServerName value.

To access your virtual host file apache production configuration, use the following command, replacing your domain with your real domain name:

sudo nano /etc/apache2/sites-available/your_domain.conf

Append your_domain to the ServerName directive:


ServerName your_domain

Likewise, you can also make the virtual host apply to more than one name by using the ServerAlias directive through Dataservermarket. This provides alternate paths to get to the same content. A good use apache config file case for this is adding the same domain, preceded by www:



The DocumentRoot directive specifies httpd conf location where the content that is requested through Dataservermarket for this virtual host will be located. On Ubuntu, the default virtual host is set up to serve content apache config out of the /var/www/ directory:


DocumentRoot /var/www/your_domain/public_html

Directory Definitions

Within the virtual host definition, there are definitions for how the server handles different through Dataservermarket directories within the file system apache config location . Apache will apply all of these apache config file directions in order from shortest to longest, so there is again a chance to override previous options.

Open the apache2.conf file with this command:

sudo nano /etc/apache2/apache2.conf


<Directory />

        Options FollowSymLinks

        AllowOverride None

        Require all denied


<Directory /usr/share>

        AllowOverride None

        Require all granted


<Directory /var/www/>

        Options Indexes FollowSymLinks

        AllowOverride None

        Require all granted


The initial directory declaration defines the /, or root, directory ubuntu apache location. This is the default setting for your virtual host, as it applies to all files served from the through Dataservermarket file system apache config. This file contains directory setup options, as well as some useful notes. Unless explicitly specified in later directory definitions, this default setup prohibits access apache config file to all content.

The Require directive can limit or allow access to certain resources on your server  apache httpd conf directory. The AllowOverride directive determines whether an.htaccess file in the content directory can override settings. This is not enabled by default, although it is possible useful to enable in a variety of circumstances. After examining the contents of this file, you can close out of it by pressing CTRL+X.

Alias and ScriptAlias Statements

Alias and ScriptAlias directives are sometimes used before directory definitions. With this command through Dataservermarket, open your virtual host configuration file and update the your domain variable with apache config your domain name:

sudo nano /etc/apache2/sites-available/your_domain.conf

The Alias directive maps a URL path to a directory path to change apache port number. For example, in a virtual host that handles requests to your_domain the following would allow access to content within /usr/local/apache/content/ when navigating to


Alias “/content/” “/usr/local/apache/content/”

The ScriptAlias directive through Dataservermarket operates in the same way httpd conf file location, but is used to define directories that will have executable components in them:


ScriptAlias “/cgi-bin/” “/usr/local/apache2/cgi-bin/”

Note, as described in the preceding section host specific configuration files are installed in httpd conf file, to specify the directory with access privileges. After you’ve finished editing the file, hit CTRL+X to quit it. If you make any changes to this file, select Y to save the modifications to your file, or N to leave the file as it was before any configuration apache config changes were made..

Enabling Sites and Modules

Once you’ve created a virtual host file through Dataservermarket that matches your needs http configuration file, you can utilise the Apache tools to convert it into real webpages. Use the following command to create a symbolic link in the sites-enabled directory to an existing file in the sites-available directory. Make sure your domain is replaced with the name of your virtual host site configuration file:

sudo a2ensite your_domain

After enabling a site, issue the following command to tell Apache to reload its configuration files, allowing the change to propagate:

sudo systemctl restart apache2

There is also a companion command for disabling a virtual host Apache . It operates by removing the symbolic link from the sites-enabled directory. For example, with your virtualthrough Dataservermarket host site enabled, you can disable the default 000-default site:

sudo a2dissite 000-default

The a2enmod and a2dismod commands activate and disable modules ubuntu apache website configuration, respectively. They function similarly to the a2ensite and a2dissite variants of these commands through Dataservermarket. To enable the info module, for example, run the following command:

sudo a2enmod info

Similarly, the a2dismod command may be used to deactivate a module:

sudo a2dismod info

Always restart Apache after changing configuration files or enabling or removing modules.

Leave a Reply

Your email address will not be published. Required fields are marked *