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/apache2Use 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.confEnvironment 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.soThe 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-enabledUbuntu helper commands commonly used for modules include:
sudo a2enmod rewrite
sudo a2dismod rewriteThese 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 80HTTPS commonly uses port 443, although the actual configuration may vary:
Listen 443The 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.confThe 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:
apache2.confprovides the main global configuration context and includes other configuration locations.ports.confdefines the TCP ports where Apache listens.- Enabled module files activate extensions and their module-specific settings.
- Enabled general configuration files provide optional shared settings.
- 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 -lsYou can also inspect one directory directly:
ls -la /etc/apache2/sites-enabledUbuntu Apache configuration reference
| Path or name | Type | Primary purpose | Activation or relationship |
|---|---|---|---|
apache2.conf | File | Primary global Apache configuration | Provides the main configuration context and includes related files |
conf-available | Directory | Stores optional general configuration fragments | Selected files are linked into conf-enabled |
conf-enabled | Directory | Identifies active general configuration fragments | Contains symbolic links to conf-available |
envvars | File | Establishes Apache-related environment variables | Used by the Apache startup and operating environment |
magic | File | Helps identify MIME types from file content signatures | Supports content-type detection |
mods-available | Directory | Stores module configuration files | Selected module configurations are linked into mods-enabled |
mods-enabled | Directory | Identifies active module configurations | Contains symbolic links to mods-available |
ports.conf | File | Specifies Apache listening TCP ports | Works with virtual hosts that match address-and-port combinations |
sites-available | Directory | Stores virtual host site files | Selected sites are linked into sites-enabled |
sites-enabled | Directory | Identifies active virtual host configurations | Contains symbolic links to sites-available |
Available and enabled directory pairs
| Available directory | Enabled directory | What is stored in available | What is stored in enabled | Configuration category |
|---|---|---|---|---|
conf-available | conf-enabled | General configuration files | Links to selected general files | Shared optional settings |
mods-available | mods-enabled | Module load and settings files | Links to selected module configurations | Apache extensions |
sites-available | sites-enabled | Virtual host files | Links to selected site configurations | Websites |
Validate and apply changes safely
Always test syntax before reloading Apache:
sudo apache2ctl configtestA 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 apache2A 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.
- Inspect
/etc/apache2/sites-enabled. - Enable the site with
sudo a2ensite example.confif appropriate. - Run
sudo apache2ctl configtest. - 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 configtestLook 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
| Environment | Common main configuration filename | Notes |
|---|---|---|
| Ubuntu | apache2.conf | Usually located at /etc/apache2/apache2.conf, with separate enabled and available directories |
Other Apache installations using httpd.conf | httpd.conf | Common 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.confis the primary Ubuntu configuration file;httpd.confis common on some other systems.conf-available,mods-available, andsites-availablestore selectable configurations.- The corresponding enabled directories contain symbolic links that identify active configurations.
envvarsestablishes Apache-related environment variables, andmagicsupports MIME type identification.ports.confcontrols listening TCP ports, while virtual host files define separate websites.- Use
apache2ctl configtestbefore applying changes withsystemctl reload apache2.
For this topic's configuration reference, see Apache configuration files.