VMware ESXi and vSphere Cluster Management

Apache Configuration Files on Ubuntu

Learn the Ubuntu Apache configuration layout, including apache2.conf, enabled and available directories, modules, ports, MIME types, environment variables, and virtual hosts.

What Apache configuration files are

Apache HTTP Server is web server software that accepts HTTP or HTTPS connections and serves web content. Apache is configured with plain-text configuration files. These files contain directives, which are Apache instructions that control server behavior.

For example, a Listen directive tells Apache to accept connections on a TCP port, while a DocumentRoot directive identifies the directory from which a website's files are served.

Configuration layouts depend on the operating system and the Apache package. httpd.conf is a historically common name for Apache's main configuration file on some systems. Ubuntu normally uses apache2.conf instead. Do not assume that instructions written for another platform use Ubuntu's paths.

The Ubuntu Apache configuration directory

On Ubuntu, the central Apache configuration directory is /etc/apache2. It separates global settings, listening ports, modules, optional configuration fragments, environment variables, MIME detection data, and website definitions.

/etc/apache2/
├── apache2.conf
├── conf-available/
├── conf-enabled/
├── envvars
├── magic
├── mods-available/
├── mods-enabled/
├── ports.conf
├── sites-available/
└── sites-enabled/

Inspect the directory with:

ls -la /etc/apache2

Use administrative permissions when reading or changing protected files. Make a backup before making significant changes.

Main file: apache2.conf

/etc/apache2/apache2.conf is Ubuntu's primary Apache configuration file. It contains settings that apply globally to the Apache service and commonly includes other configuration files.

Site-specific settings and module-specific settings are normally kept in separate files. This separation makes it easier to enable, disable, inspect, and maintain individual features without putting every directive in apache2.conf.

Available and enabled configuration snippets

Ubuntu uses a recurring available-versus-enabled convention. An available directory stores configuration that can be used. Its corresponding enabled directory contains symbolic links to the configurations that are active. A symbolic link is a filesystem entry that points to another file or directory.

General configuration: conf-available and conf-enabled

/etc/apache2/conf-available contains optional, general-purpose Apache configuration files. /etc/apache2/conf-enabled contains symbolic links to the selected files in conf-available.

A file that exists only in conf-available is not necessarily active. It becomes part of the active layout when it is linked from conf-enabled, usually with an Ubuntu helper command such as:

sudo a2enconf example.conf
sudo a2disconf example.conf

Environment variables: envvars

/etc/apache2/envvars establishes Apache-related environment variables. At a high level, these variables influence how the Apache process is started or operates, including values used by the service startup arrangement.

MIME detection: magic

/etc/apache2/magic is a text-based database used to help identify a file's MIME type from the file's initial bytes, also called its content signature. A MIME type describes the nature of data served by a web server, such as HTML, plain text, an image, or a PDF.

Correct MIME identification matters because browsers and other clients use the response content type to decide how content should be interpreted or displayed. MIME behavior can also involve other Apache configuration and system databases; the magic file is one part of that process.

Apache modules

An Apache module is an extension that supplies additional functionality, such as URL rewriting, proxying, authentication, or selected content-handling features.

/etc/apache2/mods-available contains module configuration files. A module configuration may both load a module and define settings for it. For example, a module's load file can contain a directive similar to:

LoadModule example_module /path/to/mod_example.so

The exact module name and library path depend on the installed package. /etc/apache2/mods-enabled contains symbolic links to the module configurations selected from mods-available. Enabling a module makes its configuration active and gives Apache access to the functionality supplied by that module.

ls -la /etc/apache2/mods-enabled

Ubuntu helper commands commonly used for modules include:

sudo a2enmod rewrite
sudo a2dismod rewrite

These commands manage the available-to-enabled relationship. They do not replace configuration validation.

Listening ports: ports.conf

/etc/apache2/ports.conf specifies the TCP ports on which Apache listens. A TCP port is a numbered network endpoint where a service accepts connections.

A typical HTTP listener may look like this:

Listen 80

HTTPS commonly uses port 443, although the actual configuration may vary:

Listen 443

The Listen directive establishes where Apache accepts incoming connections. This is separate from a virtual host definition. A virtual host uses an address-and-port combination to decide which website configuration handles a connection received on that listener.

Virtual host site files

A virtual host is a distinct website configuration served by one Apache instance. Virtual hosts allow one Ubuntu server and one Apache installation to serve multiple sites with independent domains, document roots, logs, access rules, and other settings.

/etc/apache2/sites-available contains available virtual host configuration files. /etc/apache2/sites-enabled contains symbolic links to the site files that are active.

A minimal illustrative site file might be:

<VirtualHost *:80>
    ServerName example.test
    DocumentRoot /var/www/example
</VirtualHost>

The file could be stored as /etc/apache2/sites-available/example.conf. Enable or disable it with:

sudo a2ensite example.conf
sudo a2dissite example.conf

The site file describes how a matching virtual host handles traffic. It does not, by itself, create a network listener if Apache is not listening on the required address and port.

How the configuration pieces work together

The configuration has several cooperating layers:

  1. apache2.conf provides the main global configuration context and includes other configuration locations.
  2. ports.conf defines the TCP ports where Apache listens.
  3. Enabled module files activate extensions and their module-specific settings.
  4. Enabled general configuration files provide optional shared settings.
  5. Enabled site files define individual virtual hosts and their website-specific behavior.

The available directories are storage and selection locations; the enabled directories identify configurations included in the active Ubuntu layout. Editing a file in an available directory alone does not necessarily activate that file. The configuration must already be enabled, or it must be enabled after the change.

To inspect the symbolic-link targets in enabled directories, use:

find /etc/apache2/conf-enabled /etc/apache2/mods-enabled /etc/apache2/sites-enabled -maxdepth 1 -type l -ls

You can also inspect one directory directly:

ls -la /etc/apache2/sites-enabled

Ubuntu Apache configuration reference

Path or nameTypePrimary purposeActivation or relationship
apache2.confFilePrimary global Apache configurationProvides the main configuration context and includes related files
conf-availableDirectoryStores optional general configuration fragmentsSelected files are linked into conf-enabled
conf-enabledDirectoryIdentifies active general configuration fragmentsContains symbolic links to conf-available
envvarsFileEstablishes Apache-related environment variablesUsed by the Apache startup and operating environment
magicFileHelps identify MIME types from file content signaturesSupports content-type detection
mods-availableDirectoryStores module configuration filesSelected module configurations are linked into mods-enabled
mods-enabledDirectoryIdentifies active module configurationsContains symbolic links to mods-available
ports.confFileSpecifies Apache listening TCP portsWorks with virtual hosts that match address-and-port combinations
sites-availableDirectoryStores virtual host site filesSelected sites are linked into sites-enabled
sites-enabledDirectoryIdentifies active virtual host configurationsContains symbolic links to sites-available

Available and enabled directory pairs

Available directoryEnabled directoryWhat is stored in availableWhat is stored in enabledConfiguration category
conf-availableconf-enabledGeneral configuration filesLinks to selected general filesShared optional settings
mods-availablemods-enabledModule load and settings filesLinks to selected module configurationsApache extensions
sites-availablesites-enabledVirtual host filesLinks to selected site configurationsWebsites

Validate and apply changes safely

Always test syntax before reloading Apache:

sudo apache2ctl configtest

A successful result normally reports Syntax OK. If Apache reports an error, read the file and line number, correct the problem, and run the test again.

After validation succeeds, reload Apache through systemd:

sudo systemctl reload apache2

A reload applies configuration changes without presenting reload as a substitute for syntax validation. If the service is not running or a change requires a restart, inspect service status and use the appropriate service operation.

Troubleshooting common configuration problems

A new site file does not serve the site

The file may exist in sites-available without being enabled in sites-enabled.

  1. Inspect /etc/apache2/sites-enabled.
  2. Enable the site with sudo a2ensite example.conf if appropriate.
  3. Run sudo apache2ctl configtest.
  4. Reload Apache after a successful test.

A module feature is unavailable

The module configuration may be present in mods-available but absent from mods-enabled. Compare both directories, enable the module with a command such as sudo a2enmod rewrite, run the syntax check, and reload after validation.

Apache is unreachable on an expected port

Review Listen directives in ports.conf. Then review the virtual host's address-and-port declaration, such as <VirtualHost *:80>. Also check Apache's active configuration and service status. A firewall or network policy can be a separate cause of unreachable traffic.

Apache fails to reload

Run:

sudo apache2ctl configtest

Look for a directive syntax error, an incorrect file reference, or an invalid virtual host block. Correct the reported file and line before attempting another reload.

Instructions mention httpd.conf

Those instructions may target another Apache package or operating system. Confirm the platform and installed package. On Ubuntu, begin with /etc/apache2/apache2.conf and the related directories under /etc/apache2.

Platform naming comparison

EnvironmentCommon main configuration filenameNotes
Ubuntuapache2.confUsually located at /etc/apache2/apache2.conf, with separate enabled and available directories
Other Apache installations using httpd.confhttpd.confCommon historical or package-specific name; the location and surrounding layout vary

Apache configuration on Windows uses a different installation directory and commonly references httpd.conf. Ubuntu paths such as /etc/apache2, sites-enabled, and Ubuntu helper commands are not universal. Verify the layout for the installed operating system and Apache package before following instructions.

Summary

  • Ubuntu's Apache configuration is centered in /etc/apache2.
  • apache2.conf is the primary Ubuntu configuration file; httpd.conf is common on some other systems.
  • conf-available, mods-available, and sites-available store selectable configurations.
  • The corresponding enabled directories contain symbolic links that identify active configurations.
  • envvars establishes Apache-related environment variables, and magic supports MIME type identification.
  • ports.conf controls listening TCP ports, while virtual host files define separate websites.
  • Use apache2ctl configtest before applying changes with systemctl reload apache2.

For this topic's configuration reference, see Apache configuration files.