This article was last reviewed for Debian 9 (Stretch).
Apache 2.4 configuration environment (Debian, repository)
Author: | Stefán Örvar Sigmundsson |
---|---|
Initial publication: | |
Last updated: | |
Written in: | English (United Kingdom) |
Apache HTTP Server is a modular, free, open-source software and the world's most popular web server. This article will demonstrate how to use the configuration environment of Apache 2.4 on Debian or its derivatives such as Ubuntu and Linux Mint.
Environment
The Debian apache2 package sets up a particular directory layout. The Apache server itself does not require that the layout be used but the helper scripts that come with the package do. It is therefore recommended that the layout be used.
Directory layout
The following table summarises the directory layout:
Path | Purpose |
---|---|
/etc/apache2/ | Apache configuration directory. |
/etc/apache2/conf-available/ | Base module configuration directory. |
/etc/apache2/conf-enabled/ | Symbolic link directory for conf-available. |
/etc/apache2/mods-available/ | Loadable module configuration directory. |
/etc/apache2/mods-enabled/ | Symbolic link directory for mods-enabled. |
/etc/apache2/sites-available/ | Virtual host configuration directory. |
/etc/apache2/sites-enabled/ | Symbolic link directory for sites-available. |
/etc/apache2/apache2.conf | General Apache configurations file. |
/etc/apache2/envvars | Environment variable file for apache2ctl script. |
/etc/apache2/magic | Data file for mod_mime_magic module. |
/etc/apache2/ports.conf | Apache configuration file. |
apache2.conf
The apache2.conf file contains Apache's general configuration. Typically only core module configuration is put into this file. More specific configuration is typically put into other files and is then included by this file.
envvars
The envvars file contains environment variables for the apache2ctl script. It is recommended that Apache be controlled via the systemctl executable instead of the apache2ctl script.
magic
The magic file contains data for the mod_mime_magic module. If the module is not used the file can be deleted.
ports.conf
The ports.conf file contains core module configuration regarding the ports to which to listen. There is no reason for it to be in a separate file and so it is recommended that its contents be copied into apache2.conf, replacing the content on line 150 (Include ports.conf
). The file can then be deleted.
conf-*
The conf-available directory contains files that configure base modules. To enable the configuration files, symbolic links are created in conf-enabled which point to files in conf-available. This allows for the configuration to be turned on and off without having to modify the configuration files since apache2.conf is set up to only include files from the conf-enabled directory. None of the default configuration files are necessary and their content is mostly commented out. They can therefore be deleted.
mods-*
The mods-available directory contains files that configure loadable modules. To enable loadable modules, symbolic links are created in mods-enabled which point to files in mods-available. This allows for the loadable modules to be turned on and off without having to modify the loadable module files since apache2.conf is set up to only include files from the mods-enabled directory.
sites-*
The sites-available directory contains files that configure virtual hosts. To enable virtual hosts, symbolic links are created in sites-enabled which point to files in sites-available. This allows for the virtual hosts to be turned on and off without having to modify the virtual host files since apache2.conf is set up to only include files from the sites-enabled directory. The two default virtual hosts, 000-default.conf and default-ssl.conf, are demonstrative templates and should be replaced by appropriately named and configured virtual host files. The file default-ssl.conf is not enabled by default.
Helper scripts
The Debian apache2 package comes with a few helper scripts that automate some processes.
apache2ctl
Configuration testing and status reporting can be performed with the apache2ctl helper script. It is recommended that only systemctl be used to control the Apache service.
a2enconf and a2disconf
Base module configuration can be easily enabled and disabled with the a2enconf and a2disconf helper scripts respectively. The configuration files to be enabled or disable, one or more, are provided as parameters to the helper scripts without the filename extension (.conf). The corresponding symbolic links in conf-enabled are then created or removed.
Example 1: To enable the custom module configuration files ErrorDocument.conf and log_config.conf:
root@computer:~# a2enconf ErrorDocument log_config Enabling conf ErrorDocument. Enabling conf log_config. To activate the new configuration, you need to run: systemctl reload apache2
Example 2: To disable the custom module configuration files ErrorDocument.conf and log_config.conf:
root@computer:~# a2disconf ErrorDocument log_config Conf ErrorDocument disabled. Conf log_config disabled. To activate the new configuration, you need to run: systemctl reload apache2
a2enmod and a2dismod
Loadable modules can be easily enabled and disabled with the a2enmod and a2dismod helper scripts respectively. The loadable modules to be enabled or disable, one or more, are provided as parameters to the helper scripts without the filename extension (.load). The corresponding symbolic links in mods-enabled are then created or removed.
Example 1: To enable the loadable modules authz_user.load and negotiation.load:
root@computer:~# a2enmod authz_user negotiation Considering dependency authz_core for authz_user: Module authz_core already enabled Enabling module authz_user. Enabling module negotiation. To activate the new configuration, you need to run: service apache2 restart
Example 2: To disable the loadable modules authz_user.load and negotiation.load:
root@computer:~# a2dismod authz_user negotiation Module authz_user disabled. Module negotiation disabled. To activate the new configuration, you need to run: service apache2 restart
a2ensite and a2dissite
Virtual hosts can be easily enabled and disabled with the a2ensite and a2dissite helper scripts respectively. The virtual hosts to be enabled or disable, one or more, are provided as parameters to the helper scripts without the filename extension (.conf). The corresponding symbolic links in sites-enabled are then created or removed.
Example 1: To enable the custom virtual hosts example.com.conf and example.org.conf:
root@computer:~# a2ensite example.com example.org Enabling site example.com. Enabling site example.org. To activate the new configuration, you need to run: systemctl reload apache2
Example 2: To disable the custom virtual hosts example.com.conf and example.org.conf:
root@computer:~# a2dissite example.com example.org Site example.com disabled. Site example.org disabled. To activate the new configuration, you need to run: systemctl reload apache2